这是XML文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="de.pentos.vrkarriere.model">
<!-- <class name="IBill" abstract="true" table="Bills"> -->
<class name="Bill" table="Bills">
<id name="id">
<generator class="identity" />
</id>
<property name="created" not-null="true" update="false" insert="false" generated="insert">
<column name="created" sql-type="timestamp" default="CURRENT_TIMESTAMP"></column>
</property>
<property name="modified" not-null="true" update="false" insert="false" generated="always">
<column name="modified" sql-type="timestamp" default="CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"></column>
</property>
<property name="fileName" not-null="true" />
</class>
</hibernate-mapping>
使用实现类一切正常 切换到接口IBill以下代码失败。
package de.pentos.vrkarriere.storage.mysql;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import de.pentos.vrkarriere.model.IBill;
import de.pentos.vrkarriere.storage.IBillDAO;
@Repository
class BillDAO implements IBillDAO {
@PersistenceContext private EntityManager entityManager;
@Override
@Transactional
public void create(final IBill bill) {
entityManager.persist(bill);
}
}
错误是
java.lang.IllegalArgumentException: Unknown entity: de.pentos.vrkarriere.model.Bill
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:294)
at com.sun.proxy.$Proxy79.persist(Unknown Source)
at de.pentos.vrkarriere.storage.mysql.BillDAO.create(BillDAO.java:21)
它应该检测Bill作为Bill Class实现IBill接口的内容 我错过了什么?