users@glassfish.java.net

RE: JPA problem with insert

From: Wim V <wim_at_pizzastop.be>
Date: Thu, 12 Jun 2008 18:53:16 +0200

Hi,

If you do not want to insert anything in that table I think this might help:
@ManyToOne(optional = true, cascade = CascadeType.REMOVE)

wim

-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: woensdag 11 juni 2008 23:44
To: users_at_glassfish.dev.java.net
Subject: JPA problem with insert

Hi. I'm new in JPA and 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;
    .....
}
---------------------------------------------------

@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!!!
[Message sent by forum member 'du27177' (du27177)]

http://forums.java.net/jive/thread.jspa?messageID=279820

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net