当我添加uniqueConstraints时,Hibernate无法创建我的实体表

时间:2015-02-24 07:49:32

标签: java hibernate

我在处理Hibernate时遇到了一些麻烦。 我有这样的实体

@Table(name = "level",
        uniqueConstraints = {@UniqueConstraint(columnNames = {"channel", "name"})})
@Entity
public class LevelEntity implements BaseEntity<Long> {


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "name")
    private String name;

    @ManyToOne(targetEntity = ChannelEntity.class)
    @JoinColumn(name = "channel")
    @Target(ChannelEntity.class)
    private ChannelEntity channel;


    public LoyaltyLevelEntity() {
    }

    @Override
    public Long getId() {
        return id;
    }
......

当我删除uniqueConstraints时,如果数据库中不存在该表,则会在部署应用程序时创建该表。但是,如果存在此参数,则表不是由hibernate创建的,而是出现异常。

我的目标是为同一频道设置唯一的ID级别名称。

例外:

org.hibernate.exception.SQLGrammarException: could not execute query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    org.hibernate.loader.Loader.doList(Loader.java:2452)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
    org.hibernate.loader.Loader.list(Loader.java:2187)
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
    org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)




java.sql.SQLException: ISAM error: no record found.
    com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:413)
    com.informix.jdbc.IfxSqli.E(IfxSqli.java:3876)
    com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2662)
    com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2578)
    com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1397)
    com.informix.jdbc.IfxPreparedStatement.f(IfxPreparedStatement.java:326)
    com.informix.jdbc.IfxPreparedStatement.a(IfxPreparedStatement.java:306)
    com.informix.jdbc.IfxPreparedStatement.<init>(IfxPreparedStatement.java:176)
    com.informix.jdbc.IfxSqliConnect.h(IfxSqliConnect.java:6707)
    com.informix.jdbc.IfxSqliConnect.prepareStatement(IfxSqliConnect.java:2470)

0 个答案:

没有答案