小编Adi*_*ant的帖子

HiLo发电机策略不起作用

我是hibernate的新手.我想要做的是用于@CollectionId为我的Address类生成一个标识符.我已经使用了Collection接口.但是当我使用@GenericGenerator并将策略设置为hilo时,它会抛出异常.这是我的代码:

@Entity
@Table(name = "USER_DETAILS")
public class UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int userId;
    private String userName;

    @ElementCollection
    @JoinTable(name="USER_ADDRESS",
        joinColumns=@JoinColumn(name="USER_ID")
    )

    @GenericGenerator(name = "hilo-gen", strategy = "hilo")
    @CollectionId(columns = { @Column(name="ADDRESS_ID") }, generator = "hilo-gen", type = @Type(type="long"))
    private Collection<Address> address = new ArrayList<Address>();

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) { …
Run Code Online (Sandbox Code Playgroud)

java collections hibernate hibernate-annotations

13
推荐指数
2
解决办法
7608
查看次数