Hi,
My requirement is to use a database view as EJB3.0 Entity. I suppose this
doesnt need any extra effort. table name tag is db view name instead of
table name. This is how it looks like
@Entity
@Table(name="Property_V")
@NamedQueries({
@NamedQuery(name="findPropsByName" ,query="Select o from PropertyView o
where o.name = :a"),
})
public class PropertyView extends PropertyViewBean {}
I have only getter methods in Entity and no setters. The issue comes only
when I declare ID column in entity.
@Column(name="ID")
public String id ;
public String getId() {
return this.id;
}
Its varchar2 in oracle database but somehow openjpa interpret it as BIGINT
and throws me below ! This is coming when I try to call the namedquery.
javax.ejb.EJBException: EJB Exception: ; nested exception is:
<openjpa-0.0.0-rnull fatal user error>
org.apache.openjpa.persistence.ArgumentException:
"com.sample.magic.poc.domain.PropertyViewBean.id" declares a column that is
not compatible with the expected type "varchar". Column details:
Full Name: Property_V.id
Type: bigint
Size: 0
Default: null
Not Null: true
at
weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:105)
at
weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:87)
at $Proxy0.getProperties(Unknown Source)
at test.junit.TestSample.testView(TestSample.java:67)
at test.junit.TestSample.main(TestSample.java:26)
Caused by: <openjpa-0.0.0-rnull fatal user error>
org.apache.openjpa.persistence.ArgumentException:
"com.tieto.magic.poc.domain.PropertyViewBean.id" declares a column that is
not compatible with the expected type "varchar". Column details:
Full Name: Property_V.id
Type: bigint
Size: 0
Default: null
Not Null: true
at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeColumn(MappingInfo.java:659)
at
org.apache.openjpa.jdbc.meta.MappingInfo.createColumns(MappingInfo.java:518)
at
org.apache.openjpa.jdbc.meta.ValueMappingInfo.getColumns(ValueMappingInfo.java:143)
at
org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy.map(StringFieldStrategy.java:79)
at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:120)
at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:80)
at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:438)
at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:403)
at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(ClassMapping.java:851)
at
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:324)
at
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:662)
at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:549)
at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:363)
at org.apache.openjpa.kernel.QueryImpl.classForName(QueryImpl.java:1563)
at
org.apache.openjpa.kernel.ExpressionStoreQuery$1.classForName(ExpressionStoreQuery.java:108)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JPQLExpressionBuilder.java:168)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaData(JPQLExpressionBuilder.java:139)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:225)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:195)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateType(JPQLExpressionBuilder.java:188)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.access$600(JPQLExpressionBuilder.java:69)
at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.populate(JPQLExpressionBuilder.java:1754)
at
org.apache.openjpa.kernel.jpql.JPQLParser.populate(JPQLParser.java:56)
at
org.apache.openjpa.kernel.ExpressionStoreQuery.populateFromCompilation(ExpressionStoreQuery.java:153)
at
org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:657)
at
org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:638)
at
org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:604)
at
org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:666)
at org.apache.openjpa.kernel.QueryImpl.compile(QueryImpl.java:573)
at kodo.kernel.KodoQuery.compile(KodoQuery.java:75)
at
org.apache.openjpa.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:892)
at
org.apache.openjpa.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl
My P.xml is a very simple one
<persistence-unit name="pocDS" transaction-type="JTA">
<jta-data-source>pocDS</jta-data-source>
<properties>
<property name="openjpa.jdbc.DBDictionary"
value="oracle(UseGetBytesForBlobs=true)"/>
</properties>
</persistence-unit>
</persistence>
This works fine with actual table in database . Only view has this problem.
Is there any specific configuration required when working with view ?
Thanks in advance,
--
View this message in context:
http://openjpa.208410.n2.nabble.com/Issue-with-ID-column-for-Database-view-as-Entity-EJB3-0-tp5237213p5237213.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.