小表叔
2016-06-14 07:17Hibernate 无法通过注解方式获取实体
org.hibernate.MappingException: Unknown entity: com.me.pojo.Cat
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1488)
at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:242)
at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:521)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:116)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
hibernate.cfg.xml
oracle.jdbc.driver.OracleDriver
tiger
jdbc:oracle:thin:@localhost:1521:ORCL
scott
org.hibernate.dialect.Oracle10gDialect
true
sessionfactory获取方式:
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry= new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
-
Cat generated by hbm2java
*/
@Entity
@Table(name = "CAT", schema = "SCOTT")
public class Cat implements java.io.Serializable {private BigDecimal id;
private String name;
private String description;
private Date createdate;
private BigDecimal motherId;public Cat() {
}public Cat(BigDecimal id) {
this.id = id;
}public Cat(BigDecimal id, String name, String description, Date createdate, BigDecimal motherId) {
this.id = id;
this.name = name;
this.description = description;
this.createdate = createdate;
this.motherId = motherId;
}@Id
@Column(name = "ID", unique = true, nullable = false, precision = 22, scale = 0)
public BigDecimal getId() {
return this.id;
}public void setId(BigDecimal id) {
this.id = id;
}@Column(name = "NAME", length = 32)
public String getName() {
return this.name;
}public void setName(String name) {
this.name = name;
}@Column(name = "DESCRIPTION", length = 100)
public String getDescription() {
return this.description;
}public void setDescription(String description) {
this.description = description;
}@Temporal(TemporalType.DATE)
@Column(name = "CREATEDATE", length = 7)
public Date getCreatedate() {
return this.createdate;
}public void setCreatedate(Date createdate) {
this.createdate = createdate;
}@Column(name = "MOTHER_ID", precision = 22, scale = 0)
public BigDecimal getMotherId() {
return this.motherId;
}public void setMotherId(BigDecimal motherId) {
this.motherId = motherId;
}
}
我在网上查了很多都是说的注解包引用错了,但是我的注解包引用的都是javax.persistence.*;请各位大神指点
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- SpringBoot + MyBatis 内部实体类属性与数据库的对应关系
- java
- hibernate
- intellij-idea
- spring
- maven
- 2个回答
- Jpa方式多对多关系中实体对象间如何通过一个实体获取另一实体的对象
- hibernate
- 权限分配
- 多对多
- jpa
- 0个回答
- hibernate set级联问题
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- 对充血模型的疑问
- 领域模型
- 0个回答
- hibernate search 字母根据注解配置的类的字段名获取配置好的 文档域名
- hibernate
- 0个回答