• 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

Question about the type of JoinColumn.

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Entity OAUser.java, I defined this:

@OneToOne
@JoinColumn(name="roleID",referencedColumnName="id")
private OARole role;

In my Entity OARole.java, there are only two field:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String roleName;

When TOPLink generate tables, the type of column roldID in table OAUser is varchar(255), and the foreign key generation failed, why?

Toplink execute "ALTER TABLE OAUSER ADD CONSTRAINT FK_OAUSER_roleID FOREIGN KEY (roleID) REFERENCES OAROLE (id)" and encounter an error, because the roleID column in OAUSER is varchar type and the id in OAROLE is number type.
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's funny.
After dinner, I try it again. No error any more.
Oh, God.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems it was waiting for your dinner. You did that, your problem solved.
Would you share what exactly it was?
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the difference.
Won't work:
@OneToOne
@JoinColumn(name="roleID",referencedColumnName="id")
private OARole role;

Works well:
@OneToOne
@JoinColumn(name="roleID")//,referencedColumnName="id")
private OARole role;

I don't know why yet.
 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Works well:
@OneToOne
@JoinColumn(name="roleID")//,referencedColumnName="id")
private OARole role;

I don't know why yet.



Can you confirm in your database, whether roleID has a join with any column or not? If yes with which Column?
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure when annotated like:

@OneToOne
@JoinColumn(name="roleID",referencedColumnName="id")
private OARole role;

the OAUSER table will generate but the column roleID is defined as varchar(255) and no Foreign Key constraint is defined for the column roleID.

if erase the attribute referencedColumnName="id":

@OneToOne
@JoinColumn(name="roleID")//,referencedColumnName="id")
private OARole role;

the roleID column in table OAUSER is defined as number(19) and a Foreign Key constraint is defined for the column roleID as well. My program goes
on and insert one row in each table.
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"If you are joining on something other than the primary-key column
of the ADDRESS table, then you must use the referencedColumnName( ) attribute.This referencedColumnName() must be unique, since this is a one-to-one relationship." I find this in "Enterprise Java Beans 3.0", it seemed that I misunderstand the referencedColumnName attribute. In my case, the roleID in OAUser is a foreign key reference the OARole table's id column which is defined as PK of OARole table.
 
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How come the below code given in EJB in Action is working and the above is not working?



I dont see any difference between the above code and code posted by mellon sun.

Regards
Sudhakar
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No difference edition doesn't work in my NetBeans6.5 before I comment that referencedColumnName="BILLING_ID" attribute ("roleID" in my code).
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

No difference edition doesn't work in my NetBeans6.5 before I comment that referencedColumnName="BILLING_ID" attribute ("roleID" in my code).



are you saying that this is a problem with the Netbeans version?In that case i would say no because i am using Netbeans 6.0 and i am facing the same problem you faced(uncommenting referencedcolumnName worked for me).

Regards
Sudhakar
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not saying it's wrong of NetBeans6.5.
I prefer to say the book given a mistake sample.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic