• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[edit]
Oops! Nevermind, I completely misread.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the CodeRanch, Gijsbert Peijs!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic