I want to use the JPA 2 metadata generator for Hibernate (version 1.1.1-Final) (in a Spring application). Since I use Mapped Superclass, which is the base for all Entities, and this class is in a different bank (for reuse), I need to display this class explicitly in XML (only for generating meta modules, since it works without any additional on time) --- Can someone tell me how to solve this in general, but this is not a question.
This mapped superclass (BusinessEntity) uses the Embedded class (BusinessId).
@SuppressWarnings("serial") @MappedSuperclass public abstract class BusinessEntity<T extends Serializable> implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; @Embedded private BusinessId<T> businessId; ... } @Embeddable public class BusinessId<T> implements Serializable { @Column(nullable = false, unique = true, name = "businessId") private long businessId; ... }
But I do not get the mapping working with the generator: If I use this orm.xml
<?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0"> <mapped-superclass class="BusinessEntity" access="FIELD"> <attributes> <id name="id"> <column nullable="false"/> <generated-value strategy="AUTO"/> </id> <embedded name="businessId"/> </attributes> </mapped-superclass> <embeddable class="BusinessId" access="FIELD"> <attributes> <basic name="businessId"> <column nullable="false" unique="true"/> </basic> </attributes> </embeddable> </entity-mappings>
The generator creates two files:
@StaticMetamodel(BusinessEntity.class) public abstract class BusinessEntity_ { public static volatile SingularAttribute<BusinessEntity, Long> id; } @StaticMetamodel(BusinessId.class) public abstract class BusinessId_ { public static volatile SingularAttribute<BusinessId, Long> businessId; }
You can see that the built-in businessId field in BuinessEntity_ is missing!
When I replace <embedded name="businessId"/> with <basic name="businessId" /> , the Generator creates this incompatible class (The Generic T cannot be resolved).
@StaticMetamodel(BusinessEntity.class) public abstract class BusinessEntity_ { public static volatile SingularAttribute<BusinessEntity, Long> id; public static volatile SingularAttribute<BusinessEntity, BusinessId<T>> businessId; }
So my question is how to match the material correctly? βOr is there a better way at all?β
Ralph
source share