openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hinshaw <chris.hins...@gmail.com>
Subject CriteriaQuery on mapped-superclass does not work with orm.xml
Date Tue, 19 Mar 2013 19:13:10 GMT
I have been switching code to use the orm.xml from the annotations for code cleanliness and
better documentation. As I was doing this I broke the ability to query an MappedSuperClass.
I know what this is not a jpa 2.0 specification but this functionality does work with openjpa.
 I have tried the newest 2.2.1 version and am still having the same problem. I did notice
that in the orm.xsd for 2.0 mapped-superclass does not support the <inheritance> tag
which may be causing my problem since I am unable to specify that the strategy will be TABLE_PER_CLASS
and this may be a prerequisite? Any ideas?


The following are my base class and the class that extends AnalyticsOperation. 

	<mapped-superclass class="com.hp.vf.server.domain.AnalyticsOperation"
		access="FIELD">

		<attributes>
			<basic name="isPublic" />
			<basic name="name" />
			<basic name="description" />

			<one-to-many name="inputs"
				target-entity="com.hp.vf.server.domain.AnalyticsOperationInput"
				fetch="LAZY" orphan-removal="true">
				<order-column />
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>

			<one-to-many name="outputs" target-entity="com.hp.vf.server.domain.metric.Metric"
				fetch="LAZY" orphan-removal="true">
				<order-column />
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>

			<one-to-one name="owner" fetch="LAZY">
				<cascade>
					<cascade-persist />
					<cascade-merge />
				</cascade>
			</one-to-one>
		</attributes>
	</mapped-superclass>

	<entity class="com.hp.vf.server.domain.RAnalyticsOperation"
		access="FIELD">
		<inheritance strategy="TABLE_PER_CLASS" />
		<attributes>
			<basic name="code" fetch="LAZY">
				<lob />
			</basic>
		</attributes>
	</entity>



In this class the clazz is the AnalyticsOperation.class from above.
    	
    	EntityManager entityManager = ThreadLocalPersistenceManager.getEntityManager();
		CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
		CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(clazz);
		
		Root<T> root = criteriaQuery.from(clazz);

		List<Predicate>  conditions = new ArrayList<Predicate>();

		if(searchColumn != null && (searchText != null && searchText.trim().length()
> 0 )){
			conditions.add(criteriaBuilder.like(root.<String> get(searchColumn), "%" + searchText.trim()
+ "%"));
		}
	...
	}


But when executing I get this exception. The DaoBase.java:141 is "Root<T> root = criteriaQuery.from(clazz);"

java.lang.IllegalArgumentException: "class com.hp.vf.server.domain.AnalyticsOperation" categorized
as "MAPPED_SUPERCLASS" should be a "ENTITY"
	at org.apache.openjpa.persistence.meta.MetamodelImpl.instantiate(MetamodelImpl.java:243)
	at org.apache.openjpa.persistence.meta.MetamodelImpl.find(MetamodelImpl.java:224)
	at org.apache.openjpa.persistence.meta.MetamodelImpl.entity(MetamodelImpl.java:126)
	at org.apache.openjpa.persistence.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:345)
	at com.hp.vf.server.dao.DaoBase.search(DaoBase.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)


Thanks,
Chris
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message