cancel
Showing results for 
Search instead for 
Did you mean: 

JPA problem during model creation: column not found in table

Former Member
0 Kudos

Hello everybody,

I am trying to deploy a Java EE application on the SAP NWDI 7.1 SP5 with NWDS. The application was not created with the studio from the scratch. It works fine on JBoss 4.2 and WebSphere 6.1.

Hibernate is used as a persistence provider. The JEE version is set to 1.5 (in application.xml: <application version="5" ... > ), however on the other app servers I used the old version.

While deploying, I get the following error:


ERRORS:
 * Model Creator: Error during model creation occured: com.sap.engine.services.orpersistence.model.ormappingmodel.ORMException: 
Column with name 'NLID' not found in table 'SECSERVICE_SV' of persistent class 'se.sync.engine.jpa.entities.bpe.security.Service'
at com.sap.engine.services.orpersistence.model.ormappingmodel.impl.ORMUtils.getColumnByName(ORMUtils.java:1516) 

The class mapped to the SECSERVICE_SV table is Service, which has the following methods:


@ManyToOne(cascade = { CascadeType.MERGE }, optional = false)
@JoinColumn(name = Application.TABLE_PREFIX + "ID")
public Application getApplication() {
	return application;
}

public void setApplication(Application app) {
	this.application = app;
}

The Application class has the following constant defined:

public static final String TABLE_PREFIX = "NL";

Does anybody have any ideas why the column "NLID" is not found in the model? Is the above usage of @JoinColumn / @ManyToOne annotations wrong? Or the problem lies somewhere else?

Thanks!

Milosz

PS: I accidentally posted this issue on a wrong forum (SAP NetWeaver Platform) - sorry for reposting...

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

The recommended policy is to use the annotations at getters, and I do not want to change this, especially because sometimes there may be no single field bound with getter/setter pair or the getter and setter argument/return type may be different than the back-end field type.

And mixing field annotations with getter/setter annotations is disallowed.

However, the problem has been (partially) solved. It turned out, that the exception was caused by the wrong interpretation of the @UniqueConstraint annotation by the SAP JPA engine. Removing this annotation made it work (although, I would still like to use this annotation - it is not crucial, but helpful). Hope to see the bug fix soon!

Thanks,

-Milosz

Edited by: Milosz Darzynkiewicz on Oct 6, 2008 1:27 PM

Former Member
0 Kudos

Hi everyone,

I'd like to raise this issue again. Is this a confirmed bug?

We're having the same problem as described above. Commenting out the uniqueConstraint solves the issue.

As I'm not (yet) too familiar with J2EE:

could I bypass this by adding a "unique = true" to the annotation of the @JoinColumn?

in other words, would:


@Table(name = "PER_TABLE1", uniqueConstraints = @UniqueConstraint(columnNames = {"IDCOLUMN"}))

be the same as:


 @JoinColumn(name = "IDCOLUMN", unique = true)
    private Term   term;

Thank you very much, best

Joerg

Former Member
0 Kudos

I will raise this issue again...

I tried the EE version 5 of application and no matter what I did - had the same problem - column not found. The interesting thing is that it doesn't matter at all what I point as a data source. The exception is thrown during building model by the SAP JPA.

The column is not missing in the database, because it is before any connection to the database. SAP's JPA seems not to add the column declared with the @JoinColumn to the persistence model of the application - at least in this case. When I changed the @JoinColumn in the code to @Column, the verification failed with similar exception but just in another place of our code (another usage of @JoinColumn).

Has anybody had a similar problem? Or maybe someone has a working JPA application with JEE version 5 and successful usage of @JoinColumn annotation?

I would be very helpful if someone could help with that.

--Milosz

Former Member
0 Kudos

Did you try declaring the annotations at the field level rather than at the getter ?

adrian_goerler
Active Participant
0 Kudos

Hi Milosz,

the error message indicates that SAP JPA recognizes the column name correctly but that the join column is missing in the database table.

Please double-check that the database table "SECSERVICE_SV" has a column "NLID". If you are running on a Open SQL/DDIC data-source, please make sure that the DDIC definition contains this column and that the table is correctly deployed before the application is deployed. If you are running on Native or Vendor SQL, please verifiy using the natice tools provieded by your database vendor.

What is striking me also, is that your are prefixing a column name with a table prefix. Is this intended?

I hope this gets you further,

-Adrian

Former Member
0 Kudos

Adrian, thank you very much for the reply.

This column definitely exists in the database table. I'm using the same database schema as on other app servers, where everything was working fine.

So the problem cannot be in the schema.

Below is the definition of this data source (I'm using three data sources) in data-sources.xml:


<data-source>
   <data-source-name>MyCompany/DataSource/BPE</data-source-name>
      <driver-name>MysqlDriver</driver-name>
      <init-connections>5</init-connections>
      <max-connections>25</max-connections>
      <!--max-time-to-wait-connection&gt;600&lt;/max-time-to-wait-connection-->

      <sql-engine>Vendor_SQL</sql-engine>
      <jdbc-1.x>
        <driver-class-name>com.mysql.jdbc.Driver</driver-class-name>
          <url>jdbc:mysql://localhost:3306/BPE?characterEncoding=UTF-8&amp;autoReconnect=true&amp;useOldAliasMetadataBehavior=true</url>
          <user-name>xxx</user-name>
          <password encrypted="false">xxx</password>
      </jdbc-1.x>
  </data-source>

How can I check whether "the table is deployed"? What does it mean for a database table? The datasources are bundled with the application (data-sources.xml is in the META-INF of ear), and the error happens during deployment... So as the application deployment fails, the datasources are not deployed as well. When I remove the Java EE 5 statement from the application.xml, the deployment succeeds and the datasources are visible as green in the management console.

Rearding your question about the prefix: yes, this is intended, it is sometimes helpful.

Best Regards,

-Milosz

adrian_goerler
Active Participant
0 Kudos

Hi Milosz,

this data source is configured for Vendor SQL. On this type of data-source, you will typically create a database table using a DDL-script or using tools that come with your database vendor. In your case, please use the MySQL tools to verify that the column in question exists in the table.

With a data-source that is configured for Open SQL, this is different. Here, you must create a database table definition using the Java Dictionary tools (DDIC) in the NWDS. Then, you create the table in the database by an additional deployment step. But, this does not apply in your case as your data source is configured for Vendor SQL.

Also, please double-check, that your data-source is pointing to the correct schema.

-Adrian