I have two jars: one contains my domain model, the other my repository running JPA w/Hibernate.
I am running a simple test where a domain model is persisted, but it fails with the following error:
Code:
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on xxx.model.product.Product.productInventory references an unknown entity: xxx.model.product.ProductInventory
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1225)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:159)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 52 more
My persistence.xml, however, should be registering all these classes:
Code:
<persistence-unit name="Catalog" transaction-type="RESOURCE_LOCAL">
<class>xxx.model.BaseModel</class>
<class>xxx.model.product.ProductInventory</class>
<class>xxx.model.product.ProductType</class>
<class>xxx.model.product.ProductVendor</class>
<class>xxx.model.product.Tag</class>
<class>xxx.model.product.Product</class>
</persistence-unit>
My BaseModel looks like this:
Code:
@MappedSuperclass
public abstract class BaseModel implements Serializable {
private static final long serialVersionUID = 1L;
/**
* @see java.lang.Object#equals(Object)
*/
public abstract boolean equals(Object object);
/**
* @see java.lang.Object#toString()
*/
public abstract String toString();
/**
* @see java.lang.Object#hashCode()
*/
public abstract int hashCode();
}
Product looks like this:
Code:
@Entity
@NamedQuery(name = "findAllProducts", query = "SELECT product FROM Product product")
public class Product extends BaseModel {
private static final long serialVersionUID = 5485516913364529115L;
@Id
private Long id;
@Version
private Long version;
@Column(unique = true)
private String jcrUuid;
@Lob
private String description;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private ProductType productType;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private ProductVendor productVendor;
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private Set<Tag> tags;
@OneToOne(cascade = CascadeType.ALL)
private ProductInventory productInventory;
private String title;
private String sku;
private Integer price;
private Float weight;
...getters/setters/toString/equals/hashCode...
While my ProductInventory (and most of the other Value Objects (Embedded) look like this:
Code:
@Embeddable
public class ProductInventory extends BaseModel {
private static final long serialVersionUID = 915352658321975360L;
private Integer stock;
private Boolean useInventory;
private Boolean allowOutOfStockPurchase;
...getters/setters/toString/equals/hashCode...
[/code]