users@glassfish.java.net

Re: Problem with insert

From: <glassfish_at_javadesktop.org>
Date: Tue, 17 Jun 2008 00:43:34 PDT

Thanks Chris for your answers!
I have another question. How I can insert into both tables? There is always some problem.
Example:
ANIMAL DOG
id----------=----id
owner name

@Entity
@Table(name="ANIMAL")
@Inheritance(strategy=InheritanceType.JOINED)
public class Animalimplements Serializable {
        @Id
        @Column(insertable = false)
        @GeneratedValue(strategy=GenerationType.IDENTITY) // database generate primary key
}
------------
@Entity
@Embeddable
@Table(name = "DOG")
@PrimaryKeyJoinColumn(name="ID", referencedColumnName="ID")
public class Dog extends Animal{
        @Column(name = "name", length = 32)
        public String name;
        public String getName{
                return name;
        }
}
------------------
ID in table DOG is Generated Always.

im my Java class I have
Animal animal = new Animal();
Dog dog = new Dog ();

I tried everithing:
EntityManager em = null;
...
em.merge(animal);
em.merge(dog);
error: Id is generated always
....
only:
em.merge(dog)
also error: A value cannot be specified for column "ID" which is defined as GENERATED ALWAYS.

....

Any sugestions?
[Message sent by forum member 'du27177' (du27177)]

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