[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - JPA problem with insert
tovar
do-not-reply at jboss.com
Wed Jun 11 15:33:21 EDT 2008
Hi. I have problem with inserting in database.
I don't know how to insert object and disable an attempt of inserting in related tables.
example:
@Entity
@Table(name = "MAIN_TABLE", schema = "SCH")
@Inheritance(strategy=InheritanceType.JOINED)
public class MainClass extends MainDataObject {
@Id
public Integer id;
@Column(name = "session", nullable = false)
@ManyToOne(optional = false, cascade = CascadeType.PERSIST)
@JoinColumn(name="session",referencedColumnName="id")
public ProblematicSession session;
@Column(name = "destination_member_state", nullable = false, length = 2)
@ManyToOne(optional = false, cascade = CascadeType.PERSIST)
@JoinColumn(name="destination_member_state",referencedColumnName="country_code")
public Country destinationMemberState;
---------------------------------------------------
@Entity
@Table(name = "PROBBLEMATICTABLE", schema = "SCH")
public class ProblematicSession extends MainDataObject {
@Id
@Column(insertable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer id;
Database create ID, so I put insertable = false and strategy=GenerationType.IDENTITY.
When I insert into MAIN_TABLE, how to disable an attempt of inserting in related table (PROBBLEMATICTABLE).
if I set for example ProblematicSession.id = 1 error is:
This existing value was either provided via an initializer or by calling the setter method. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.
If I set ProblematicSession.id = null, also try to insert into PROBBLEMATICTABLE. A do not want that!!!
Also I have table where database do not insert primary key, and there is no problem (Country).
@Id
@Column(name = "country_code", nullable = false, length = 2)
public String countryCode;
public String getCountryCode() {
return countryCode;
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4157485#4157485
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4157485
More information about the jboss-user
mailing list