Caused by: javax.persistence.PersistenceException: [PersistenceUnit: com.rootls] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:286)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 50 more
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: user, for columns: [org.hibernate.mapping.Column(roles)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:305)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:289)
at org.hibernate.mapping.Property.isValid(Property.java:238)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:468)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1294)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1736)
at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 56 more
@MappedSuperclass
public abstract class IdEntity /*extends AbstractPersistable<Integer>*/
implements Serializable,Cloneable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.setId(id);
}
}
@Entity
@Table(name = "user")
//@AttributeOverride( name="id", column = @Column(name="id") )
public class User extends IdEntity{
@ManyToMany
@JoinTable(name = "user_role",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
@Entity
@Table(name = "role")
//@AttributeOverride( name="id", column = @Column(name="id") )
public class Role extends IdEntity {
private Set<User> users = new HashSet<User>();
@ManyToMany(mappedBy = "roles")
public Set<User> getUsers() {
return users;
}
public void setUsers(Set<User> users) {
this.users = users;
}
项目地址:https://github.com/luowei/mvn-test
sql脚本:
create table user(
id int(11) primary key auto_increment,
username varchar(100) not null,
password varchar(92) not null,
email varchar(50)
);
create table role(
id int(11) primary key auto_increment,
role_name varchar(30) not null,
role_description varchar(100),
create_time timestamp not null
);
create table user_role(
id int(11) primary key auto_increment,
user_id int(11) not null,
role_id int(11) not null,
constraint uq_user_role unique(user_id, role_id)
);
注解要么全在属性上,要么全在getter上,混合就会报“Could not determine type for”
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。