WARNING: This server is unstable and will be retired in the next days. If you want to keep this forum available, please request immediately a migration on the Nabble Support forum. Forums that don't receive any migration request will be deleted forever.

Problem with TABLE_PER_CLASS inheritance strategy

View: New views
5 Messages — Rating Filter:   Alert me  

Problem with TABLE_PER_CLASS inheritance strategy

by Daniel Le Berre :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

I was trying the various inheritance strategies on a very simple example:
Employe extends MyCustomer extends Person

JOINED and SINGLE_TABLE  strategies work fine with default options, but
using TABLE_PER_CLASS, I got the following exception:

Exception in thread "Thread-48" javax.persistence.PersistenceException:
org.hibernate.MappingException: Cannot use identity column key
generation with <union-subclass> mapping for: ili.sem4.Employe
    at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
    at
org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
    at
org.objectweb.easybeans.persistence.JPersistenceContext.init(JPersistenceContext.java:72)
    at
org.objectweb.easybeans.persistence.JPersistenceContext.<init>(JPersistenceContext.java:65)
    at
org.objectweb.easybeans.persistence.PersistenceUnitManager.<init>(PersistenceUnitManager.java:60)
    at
org.objectweb.easybeans.persistence.xml.PersistenceXmlFileAnalyzer.analyzePersistenceXmlFile(PersistenceXmlFileAnalyzer.java:139)
    at
org.objectweb.easybeans.container.JContainer3.start(JContainer3.java:254)
    at
org.objectweb.easybeans.server.ContainersMonitor.checkContainer(ContainersMonitor.java:226)
    at
org.objectweb.easybeans.server.ContainersMonitor.run(ContainersMonitor.java:120)
Caused by: org.hibernate.MappingException: Cannot use identity column
key generation with <union-subclass> mapping for: ili.sem4.Employe
    at
org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:67)
    at
org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
    at
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
    at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
    ... 8 more

I haven't found much details in the EJB 3.0 persistence specification.

I use MySQL  as a backend. I am wondering if it is a database specific
issue ?
 
Please find below the code on my entities (from Enterprise JavaBeans 3.0
5th edition).

    Daniel

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
//
@DiscriminatorColumn(name="DISCRIMINATOR",discriminatorType=DiscriminatorType.CHAR)
// @DiscriminatorValue("P")
public class Person {

    private int id;

    private String firstName;

    private String lastName;

    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}


@Entity
//@DiscriminatorValue("C")
public class MyCustomer extends Person {

    private String street;

    private String city;

    private String state;

    private String zip;

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

}

@Entity
//@DiscriminatorValue("E")
public class Employe extends MyCustomer {

    private int employeId;

    public int getEmployeId() {
        return employeId;
    }

    public void setEmployeId(int employeId) {
        this.employeId = employeId;
    }

}
 



--
You receive this message as a subscriber of the easybeans@... mailing list.
To unsubscribe: mailto:easybeans-unsubscribe@...
For general help: mailto:sympa@...?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

Re: Problem with TABLE_PER_CLASS inheritance strategy

by benoitf :: Rate this Message:

| View Threaded | Show Only this Message

    Hi Daniel,

I think you should look at @MappedSuperClass annotation.

Best Regards,

Florent

Daniel Le Berre wrote:
Hi,

I was trying the various inheritance strategies on a very simple example:
Employe extends MyCustomer extends Person

JOINED and SINGLE_TABLE  strategies work fine with default options, but using TABLE_PER_CLASS, I got the following exception:

Exception in thread "Thread-48" javax.persistence.PersistenceException: org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: ili.sem4.Employe
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
   at org.objectweb.easybeans.persistence.JPersistenceContext.init(JPersistenceContext.java:72)
   at org.objectweb.easybeans.persistence.JPersistenceContext.<init>(JPersistenceContext.java:65)
   at org.objectweb.easybeans.persistence.PersistenceUnitManager.<init>(PersistenceUnitManager.java:60)
   at org.objectweb.easybeans.persistence.xml.PersistenceXmlFileAnalyzer.analyzePersistenceXmlFile(PersistenceXmlFileAnalyzer.java:139)
   at org.objectweb.easybeans.container.JContainer3.start(JContainer3.java:254)
   at org.objectweb.easybeans.server.ContainersMonitor.checkContainer(ContainersMonitor.java:226)
   at org.objectweb.easybeans.server.ContainersMonitor.run(ContainersMonitor.java:120)
Caused by: org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: ili.sem4.Employe
   at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:67)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
   ... 8 more

I haven't found much details in the EJB 3.0 persistence specification.

I use MySQL  as a backend. I am wondering if it is a database specific issue ?

Please find below the code on my entities (from Enterprise JavaBeans 3.0 5th edition).

   Daniel

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
// @DiscriminatorColumn(name="DISCRIMINATOR",discriminatorType=DiscriminatorType.CHAR)
// @DiscriminatorValue("P")
public class Person {

   private int id;

   private String firstName;

   private String lastName;

   @Id
   @GeneratedValue
   public int getId() {
       return id;
   }

   public void setId(int id) {
       this.id = id;
   }

   public String getFirstName() {
       return this.firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
}


@Entity
//@DiscriminatorValue("C")
public class MyCustomer extends Person {

   private String street;

   private String city;

   private String state;

   private String zip;

   public String getCity() {
       return city;
   }

   public void setCity(String city) {
       this.city = city;
   }

   public String getState() {
       return state;
   }

   public void setState(String state) {
       this.state = state;
   }

   public String getStreet() {
       return street;
   }

   public void setStreet(String street) {
       this.street = street;
   }

   public String getZip() {
       return zip;
   }

   public void setZip(String zip) {
       this.zip = zip;
   }

}

@Entity
//@DiscriminatorValue("E")
public class Employe extends MyCustomer {

   private int employeId;

   public int getEmployeId() {
       return employeId;
   }

   public void setEmployeId(int employeId) {
       this.employeId = employeId;
   }

}



-- You receive this message as a subscriber of the easybeans@... mailing list. To unsubscribe: easybeans-unsubscribe@... For general help: sympa@... ObjectWeb mailing lists service home page: http://www.objectweb.org/wws



--
You receive this message as a subscriber of the easybeans@... mailing list.
To unsubscribe: mailto:easybeans-unsubscribe@...
For general help: mailto:sympa@...?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

Re: Problem with TABLE_PER_CLASS inheritance strategy

by Daniel Le Berre :: Rate this Message:

| View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Florent,

Florent BENOIT a écrit :
>     Hi Daniel,
>
> I think you should look at @MappedSuperClass annotation.

I do not think so. @MappedSuperClass is for non entity classes.
http://java.sun.com/javaee/5/docs/api/javax/persistence/MappedSuperclass.html

I would like Person to be an entity.

It looks like an implementation problem.

Maybe I should use another persistence framework to see if it works file.

I noticed an openjpa persistence  provider in the examples
persistence.xml file. How can I activate it in easybeans?

        Daniel

> Best Regards,
>
> Florent
>
> Daniel Le Berre wrote:
>> Hi,
>>
>> I was trying the various inheritance strategies on a very simple example:
>> Employe extends MyCustomer extends Person
>>
>> JOINED and SINGLE_TABLE  strategies work fine with default options,
>> but using TABLE_PER_CLASS, I got the following exception:
>>
>> Exception in thread "Thread-48"
>> javax.persistence.PersistenceException:
>> org.hibernate.MappingException: Cannot use identity column key
>> generation with <union-subclass> mapping for: ili.sem4.Employe
>>    at
>> org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
>>
>>    at
>> org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
>>
>>    at
>> org.objectweb.easybeans.persistence.JPersistenceContext.init(JPersistenceContext.java:72)
>>
>>    at
>> org.objectweb.easybeans.persistence.JPersistenceContext.<init>(JPersistenceContext.java:65)
>>
>>    at
>> org.objectweb.easybeans.persistence.PersistenceUnitManager.<init>(PersistenceUnitManager.java:60)
>>
>>    at
>> org.objectweb.easybeans.persistence.xml.PersistenceXmlFileAnalyzer.analyzePersistenceXmlFile(PersistenceXmlFileAnalyzer.java:139)
>>
>>    at
>> org.objectweb.easybeans.container.JContainer3.start(JContainer3.java:254)
>>    at
>> org.objectweb.easybeans.server.ContainersMonitor.checkContainer(ContainersMonitor.java:226)
>>
>>    at
>> org.objectweb.easybeans.server.ContainersMonitor.run(ContainersMonitor.java:120)
>>
>> Caused by: org.hibernate.MappingException: Cannot use identity column
>> key generation with <union-subclass> mapping for: ili.sem4.Employe
>>    at
>> org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:67)
>>
>>    at
>> org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
>>
>>    at
>> org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
>>    at
>> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
>>
>>    at
>> org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
>>
>>    ... 8 more
>>
>> I haven't found much details in the EJB 3.0 persistence specification.
>>
>> I use MySQL  as a backend. I am wondering if it is a database specific
>> issue ?
>>
>> Please find below the code on my entities (from Enterprise JavaBeans
>> 3.0 5th edition).
>>
>>    Daniel
>>
>> @Entity
>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
>> //
>> @DiscriminatorColumn(name="DISCRIMINATOR",discriminatorType=DiscriminatorType.CHAR)
>>
>> // @DiscriminatorValue("P")
>> public class Person {
>>
>>    private int id;
>>
>>    private String firstName;
>>
>>    private String lastName;
>>
>>    @Id
>>    @GeneratedValue
>>    public int getId() {
>>        return id;
>>    }
>>
>>    public void setId(int id) {
>>        this.id = id;
>>    }
>>
>>    public String getFirstName() {
>>        return this.firstName;
>>    }
>>
>>    public void setFirstName(String firstName) {
>>        this.firstName = firstName;
>>    }
>>
>>    public String getLastName() {
>>        return lastName;
>>    }
>>
>>    public void setLastName(String lastName) {
>>        this.lastName = lastName;
>>    }
>> }
>>
>>
>> @Entity
>> //@DiscriminatorValue("C")
>> public class MyCustomer extends Person {
>>
>>    private String street;
>>
>>    private String city;
>>
>>    private String state;
>>
>>    private String zip;
>>
>>    public String getCity() {
>>        return city;
>>    }
>>
>>    public void setCity(String city) {
>>        this.city = city;
>>    }
>>
>>    public String getState() {
>>        return state;
>>    }
>>
>>    public void setState(String state) {
>>        this.state = state;
>>    }
>>
>>    public String getStreet() {
>>        return street;
>>    }
>>
>>    public void setStreet(String street) {
>>        this.street = street;
>>    }
>>
>>    public String getZip() {
>>        return zip;
>>    }
>>
>>    public void setZip(String zip) {
>>        this.zip = zip;
>>    }
>>
>> }
>>
>> @Entity
>> //@DiscriminatorValue("E")
>> public class Employe extends MyCustomer {
>>
>>    private int employeId;
>>
>>    public int getEmployeId() {
>>        return employeId;
>>    }
>>
>>    public void setEmployeId(int employeId) {
>>        this.employeId = employeId;
>>    }
>>
>> }
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> --
>> You receive this message as a subscriber of the easybeans@... mailing list.
>> To unsubscribe: mailto:easybeans-unsubscribe@...
>> For general help: mailto:sympa@...?subject=help
>> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>>  
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the easybeans@... mailing list.
> To unsubscribe: mailto:easybeans-unsubscribe@...
> For general help: mailto:sympa@...?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

- --
             Daniel Le Berre mailto:leberre@...
             MCF,    CRIL-CNRS FRE 2499,    Universite d'Artois
             http://www.cril.univ-artois.fr/~leberre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFFw0sKqVioN+Yc2ggRAozFAKC1Ghsk3Jwl2g3P8cR9HBBtnkzhGwCeO/95
iPej7/jmXuWQq6vWfXuWLWo=
=Bmtn
-----END PGP SIGNATURE-----



--
You receive this message as a subscriber of the easybeans@... mailing list.
To unsubscribe: mailto:easybeans-unsubscribe@...
For general help: mailto:sympa@...?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

Re: Problem with TABLE_PER_CLASS inheritance strategy

by benoitf :: Rate this Message:

| View Threaded | Show Only this Message

    Hi Daniel,

Sorry, I didn't see that you provided a java source code at the end of the file.
You have to change the strategy used on the primary key field:

   @Id
   @GeneratedValue(strategy=GenerationType.TABLE)
   public int getId() {
       return id;
   }

Also, note that TABLE_PER_CLASS is optional in the specification. Some vendors may not implement it.

Regards,

Florent

Daniel Le Berre wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Florent,

Florent BENOIT a écrit :
  
    Hi Daniel,

I think you should look at @MappedSuperClass annotation.
    

I do not think so. @MappedSuperClass is for non entity classes.
http://java.sun.com/javaee/5/docs/api/javax/persistence/MappedSuperclass.html

I would like Person to be an entity.

It looks like an implementation problem.

Maybe I should use another persistence framework to see if it works file.

I noticed an openjpa persistence  provider in the examples
persistence.xml file. How can I activate it in easybeans?

	Daniel



--
You receive this message as a subscriber of the easybeans@... mailing list.
To unsubscribe: mailto:easybeans-unsubscribe@...
For general help: mailto:sympa@...?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

Re: Problem with TABLE_PER_CLASS inheritance strategy

by Daniel Le Berre :: Rate this Message:

| View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Florent BENOIT a écrit :

>     Hi Daniel,
>
> Sorry, I didn't see that you provided a java source code at the end of
> the file.
> You have to change the strategy used on the primary key field:
>
>    @Id
>    @GeneratedValue(strategy=GenerationType.TABLE)
>    public int getId() {
>        return id;
>    }
Thanks. Could you explain me why?

> Also, note that TABLE_PER_CLASS is optional in the specification. Some
> vendors may not implement it.

ok, thanks for the information.

        Daniel

> Regards,
>
> Florent
>
> Daniel Le Berre wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi Florent,
>>
>> Florent BENOIT a écrit :
>>  
>>>     Hi Daniel,
>>>
>>> I think you should look at @MappedSuperClass annotation.
>>>    
>>
>> I do not think so. @MappedSuperClass is for non entity classes.
>> http://java.sun.com/javaee/5/docs/api/javax/persistence/MappedSuperclass.html
>>
>> I would like Person to be an entity.
>>
>> It looks like an implementation problem.
>>
>> Maybe I should use another persistence framework to see if it works file.
>>
>> I noticed an openjpa persistence  provider in the examples
>> persistence.xml file. How can I activate it in easybeans?
>>
>> Daniel
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the easybeans@... mailing list.
> To unsubscribe: mailto:easybeans-unsubscribe@...
> For general help: mailto:sympa@...?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

- --
             Daniel Le Berre mailto:leberre@...
             MCF,    CRIL-CNRS FRE 2499,    Universite d'Artois
             http://www.cril.univ-artois.fr/~leberre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFFw1dbqVioN+Yc2ggRAhj0AJ0UMqlcTPQUZCjJnwUpvH5u7SWzqACfXhTm
/BTIF1kpJcIhDbwbva2qWHg=
=Onvn
-----END PGP SIGNATURE-----



--
You receive this message as a subscriber of the easybeans@... mailing list.
To unsubscribe: mailto:easybeans-unsubscribe@...
For general help: mailto:sympa@...?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws