-->
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.  [ 6 posts ] 
Author Message
 Post subject: oneToMany Asso. cannot set duplidate entry to DB
PostPosted: Mon Jun 18, 2007 3:13 am 
Newbie

Joined: Fri May 25, 2007 4:42 am
Posts: 13
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1/3.2


hi, i have a simple oneToMany Association,
project -->* ChangeHistoryEntry

through hibernate-Annotation can auto. create 3 tables, project-Table, ChangeHisEntry-Table, and a project_changehistoryentries(association Table).

here is the code in project.java:

@OneToMany(targetEntity = ChangeHistoryEntry.class)
@JoinTable(
name="pro_changehistoryentries",
// joinColumns = { @JoinColumn( name="PROJECT", nullable = false) },
joinColumns = { @JoinColumn( name="PROJECT", nullable = false) },
inverseJoinColumns = @JoinColumn( name="CHANGE_HISTORY_ENTRY")
)
//or default @OneToMany
private Collection <ChangeHistoryEntry> changeHistoryEntries = new HashSet<ChangeHistoryEntry> (0); //1 -> *


public Collection getChangehistoryentrieses() {
return this.changeHistoryEntries;
}


public void setChangehistoryentrieses(Collection<ChangeHistoryEntry> changeHistoryEntries) {
this.changeHistoryEntries = changeHistoryEntries;
}


Last edited by oftsky on Mon Jun 18, 2007 6:28 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: can not set duplicate entry
PostPosted: Mon Jun 18, 2007 5:57 am 
Newbie

Joined: Fri May 25, 2007 4:42 am
Posts: 13
see next post


Last edited by oftsky on Mon Jun 18, 2007 6:29 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: new Problem by setChangeHistoryEntries
PostPosted: Mon Jun 18, 2007 6:01 am 
Newbie

Joined: Fri May 25, 2007 4:42 am
Posts: 13
by setChangeHistoryEntries(ChangeHistoryEntrie(s))
if one of this ChangeHistoryEntrie(s) has been already set to another project and this relation has existed in that association Table pro_ChangeHistoryEntries,
if i set this ChangeHistoryEntries to a new project,
get the following failue message:
java.sql.BatchUpdateException: Duplicate entry '402880f1133e27c601133e2902200006' for key 1


the ids were all generated auto. like this:
@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "PRO_ID")
private String id;

anybody has idea?


Last edited by oftsky on Mon Jun 18, 2007 11:42 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: the problem
PostPosted: Mon Jun 18, 2007 7:55 am 
Newbie

Joined: Fri May 25, 2007 4:42 am
Posts: 13
the problem is,

the hibernate annotation auto created a rowId(i think like TableId) changeHistoryEntries_CHA_ID and his index into the associationTable project_change_history_entry. That is why one cha_id can only be set to one project.

how can i create this associationTable without the rowId?

again the code:

@Entity
@Table(name="project")

public class Project implements java.io.Serializable {

// Fields

@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "PRO_ID")
private String id;

....
@OneToMany(cascade={CascadeType.ALL})
private Collection <ChangeHistoryEntry> changeHistoryEntries = new HashSet<ChangeHistoryEntry> (0); //1 -> *

....

}

@Entity
@Table(name="change_history_entry")

public class ChangeHistoryEntry implements java.io.Serializable {

// Fields

@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "CHA_ID")
private String id;
....}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 4:22 pm 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

Try annotating your Collection with @CollectionId to force the creation of a separate column to store the primary key.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 12:45 pm 
Newbie

Joined: Fri May 25, 2007 4:42 am
Posts: 13
sorry, my question is false.

this is a 1->* relationship. Of course, each Object from *.side can only belong to 1 Object from 1.side.

sorry


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.