java setcolumns_java – List或Set的JPA映射

作为ORM的新手,我想找到一种方法来定义一个简单(意味着没有额外的实体)映射实体中的一个列表(或一组)字符串.我找到了这个样本:

import java.util.Set;

import javax.persistence.CollectionTable;

import javax.persistence.Column;

import javax.persistence.ElementCollection;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

@Entity

public class Book {

@Id

@GeneratedValue

private Long id;

@ElementCollection

@CollectionTable(name = "tags")

private Set tags;

public Long getId() {

return id;

}

public void setId(Long id) {

this.id = id;

}

public Set getTags() {

return tags;

}

public void setTags(Set tags) {

this.tags = tags;

}

}

这似乎符合我的需要.但是,使用Eclipse的hibernate3-maven-plugin处理这个类:2.2:hbm2ddl,我最终得到以下错误:

[ERROR] Failed to execute goal

org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl (default) on

project test-database: Execution default of goal

org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl failed: Could

not determine type for: java.util.Set, at table: Book, for columns:

[org.hibernate.mapping.Column(tags)] -> [Help 1]

指定@ElementCollection(targetClass = String.class)没有帮助.将列定义添加到tags字段(@Column(name =“tags”,columnDefinition =“character varying(255)”,nullable = false))会导致成功构建但生成此SQL:

create table Book (

id int8 not null,

tags character varying (255) not null,

primary key (id)

);

这不是我想要的,因为我期望最终得到一个链接到books表的标签表.有人能指出我正确的方向吗?谢谢.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值