开发者社区> 问答> 正文

当使用 @MappedSuperclass,@Entity,@ManyToMany 报:Could not determine type for

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)
    );

展开
收起
小旋风柴进 2016-03-16 18:12:08 3908 0
1 条回答
写回答
取消 提交回答
  • 注解要么全在属性上,要么全在getter上,混合就会报“Could not determine type for”

    2020-03-30 19:57:00
    赞同 展开评论 打赏
问答分类:
SQL
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Froma single droplet toafull b 立即下载
Semantic Search--Fast Results from Large,Foreign Language Corpora 立即下载
Path to 400M* Members: LinkedI 立即下载