-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: OneToMany mappings issue
PostPosted: Wed Feb 01, 2006 12:48 pm 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
I have an entity bean that contain 2 list of the same entity:
Code:
public Class Toto {
  @OneToMany()
  public List<Customer> getNiceCustomers() {..}

  @OneToMany()
  public List<Customer> getBadCustomers() {..}
}

If I writte bean like previous one, when I try to add customers in my Toto, I add an exception:
Code:
16:44:34,094 WARN  [JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
16:44:34,094 ERROR [JDBCExceptionReporter] Duplicate entry '0' for key 1
16:44:34,094 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert collection: [Toto.niceCustomers#1]
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)


In the DB I can see that only one table as been created for mapping the 2 collections.

To workaound that issue I need to explicitely declared JoinTable:
Code:
public Class Toto {
  @OneToMany()
  @JoinTable(name = "Toto_niceCustomer", joinColumns = { @JoinColumn(name = "toto_id") }, inverseJoinColumns = @JoinColumn(name = "position_id"))
  public List<Customer> getNiceCustomers() {..}

  @OneToMany()
  @JoinTable(name = "Toto_BadCustomer", joinColumns = { @JoinColumn(name = "toto_id") }, inverseJoinColumns = @JoinColumn(name = "position_id"))
  public List<Customer> getBadCustomers() {..}
}



Will it be possible that hibernate automatically create the 2 join tables ?
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 8:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
OVerride EJB3NamingStrategy

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.