You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by tschuler <th...@opentext.com> on 2012/12/19 13:14:33 UTC
Entity inheritance
Hi!
We are using entities and got problems with entity inheritance.
E.g. If we use the entity manager to get a non-existing (inherited) entity
we got an error message instead of a null object:
Assume a BaseEntity with @Inheritance(strategy =
InheritanceType.TABLE_PER_CLASS) and at least an ID column.
A TestExtendedEntity extending BaseEntity matching to a table in a MSSQL
database.
-> entityManager.find(TestExtendedEntity.class, unknownId) results in:
Exception in thread "main" javax.ejb.EJBException: The bean encountered a
non-application exception; nested exception is:
<openjpa-2.2.0-r422266:1244990 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Invalid object name
'BaseEntity'. {prepstmnt 362917156 SELECT t0.sId, t0.lVersion, t0.sValue
FROM BaseEntity t0 WHERE t0.sId = ? [params=?]} [code=208, state=S0002]
FailedObject: unknownId [org.apache.openjpa.util.StringId]
[java.lang.String]
[...]
Caused by: <openjpa-2.2.0-r422266:1244990 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Invalid object name
'BaseEntity'. {prepstmnt 362917156 SELECT t0.sId, t0.lVersion, t0.sValue
FROM BaseEntity t0 WHERE t0.sId = ? [params=?]} [code=208, state=S0002]
FailedObject: unknownId [org.apache.openjpa.util.StringId]
[java.lang.String]
[...]
Caused by: java.lang.Exception:
org.apache.openjpa.lib.jdbc.ReportingSQLException: Invalid object name
'BaseEntity'. {prepstmnt 362917156 SELECT t0.sId, t0.lVersion, t0.sValue
FROM BaseEntity t0 WHERE t0.sId = ? [params=?]} [code=208, state=S0002]
[...]
I would expect a null object instead as described in the EntityManager
interface.
Could you imagine a cause for the error and how to avoid it?
Best regards,
Thomas
--
View this message in context: http://openejb.979440.n4.nabble.com/Entity-inheritance-tp4659819.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Entity inheritance
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
does it work with an existing id?
wonder if it couldn't be a db mappin gissue
that's said maybe the OpenJPA list is more adapted
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2012/12/19 tschuler <th...@opentext.com>:
> Hi!
>
> We are using entities and got problems with entity inheritance.
> E.g. If we use the entity manager to get a non-existing (inherited) entity
> we got an error message instead of a null object:
> Assume a BaseEntity with @Inheritance(strategy =
> InheritanceType.TABLE_PER_CLASS) and at least an ID column.
> A TestExtendedEntity extending BaseEntity matching to a table in a MSSQL
> database.
> -> entityManager.find(TestExtendedEntity.class, unknownId) results in:
>
> Exception in thread "main" javax.ejb.EJBException: The bean encountered a
> non-application exception; nested exception is:
> <openjpa-2.2.0-r422266:1244990 fatal general error>
> org.apache.openjpa.persistence.PersistenceException: Invalid object name
> 'BaseEntity'. {prepstmnt 362917156 SELECT t0.sId, t0.lVersion, t0.sValue
> FROM BaseEntity t0 WHERE t0.sId = ? [params=?]} [code=208, state=S0002]
> FailedObject: unknownId [org.apache.openjpa.util.StringId]
> [java.lang.String]
> [...]
> Caused by: <openjpa-2.2.0-r422266:1244990 fatal general error>
> org.apache.openjpa.persistence.PersistenceException: Invalid object name
> 'BaseEntity'. {prepstmnt 362917156 SELECT t0.sId, t0.lVersion, t0.sValue
> FROM BaseEntity t0 WHERE t0.sId = ? [params=?]} [code=208, state=S0002]
> FailedObject: unknownId [org.apache.openjpa.util.StringId]
> [java.lang.String]
> [...]
> Caused by: java.lang.Exception:
> org.apache.openjpa.lib.jdbc.ReportingSQLException: Invalid object name
> 'BaseEntity'. {prepstmnt 362917156 SELECT t0.sId, t0.lVersion, t0.sValue
> FROM BaseEntity t0 WHERE t0.sId = ? [params=?]} [code=208, state=S0002]
> [...]
>
> I would expect a null object instead as described in the EntityManager
> interface.
>
> Could you imagine a cause for the error and how to avoid it?
>
> Best regards,
> Thomas
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Entity-inheritance-tp4659819.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Entity inheritance
Posted by zeeman <ha...@fastmail.us>.
Be sure baseEntity is an abstract class with @MappedSupperClass annotation on
it. Don't put @entity on it as that won't work.
--
View this message in context: http://openejb.979440.n4.nabble.com/Entity-inheritance-tp4659819p4659896.html
Sent from the OpenEJB User mailing list archive at Nabble.com.