• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JPA Unidirectional 1to1 mapping issue: A Foreign key has the wrong number of column. should be 2

 
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I've goggled around, but haven't found anything that's helped me out.

I'm getting the error message:
A JPA error occurred (Unable to build EntityManagerFactory): A Foreign key referring Credentials from Customer has the wrong number of column. should be 2

I want a unidirectional one-to-one mapping from Customer to Credentials -- I do not need or want any reference from Credentials to Customer.

So I defined in Customer:

JPA is most unhappy about it.

Any google result I looked at either discussed ManyToOne mappings, or composite foreign keys, which are not applicable here.

Any insights?

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return type is missing

Strange. What does Credentials look like ? What kind of indexes (pks) are on it ? Is credentialsId unique ?
 
Saloon Keeper
Posts: 10430
223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[edit]
Oops! Nevermind, I completely misread.
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Christophe Verré wrote:The return type is missing

The ... is a macro!

Strange. What does Credentials look like ?


Just a POJO. It has no reference back to Customer.

What kind of indexes (pks) are on it ? Is credentialsId unique ?


There isn't any schema yet. Hibernate isn't getting to the point where it creates the actual tables, so the database is empty.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

There isn't any schema yet. Hibernate isn't getting to the point where it creates the actual tables, so the database is empty.


But the Credentials entity has some annotations in it, hasn't it ? @Id and other kind of annotations. Can you post your Credentials class ?
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, here's Credentials:


There's a reason for the public fields as opposed to a bean-patterned class. But that shouldn't affect JPA.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"extends Model" ? What's in there ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a tool to generate the schema ? Or are you letting Hibernate generate the schema at startup, via the hibernate.hbm2ddl.auto property in persistence.xml ?

Also, I don't know if this is related, but what did you set hibernate.dialect to ?
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Christophe Verré wrote:"extends Model" ? What's in there ?



Well, that was the clue. Removing that causes JPA to correctly create the schema.

Model is a Decorator from a framework I'm evaluating. Apparently it's doing something that's interfering with my annotations....

Thanks Christophe, I might not have tried removing that if you hadn't poked at it!

Now I guess it's time to ping the framework guys...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you've found the source of the problem.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi BB,

This discussion is old and you've probably fixed your problems and are happy with the (fantastic imho) Play framework or moved on to another.

The error is caused by the fact that you try to extend play.jpa.Model which normally is a good plan but it assumes you let Play generate a Long as your id automatically. In this case you're using an Integer as id which you manage yourself. Play supports this without any problem but you have to extend the GenericModel super class instead of Model. That will (or would have) fixed your problems.
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup.... sorry I should have followed up on this when the problem was resolved.

Extending GenericModel did the trick as the schema I am mapping onto is old and I could not change the id's to longs as it is used by many other legacy applications that cannot be changed.
 
Bartender
Posts: 4101
63
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the CodeRanch, Gijsbert Peijs!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!