Hibernate映射相同列两次并插入

时间:2015-10-12 08:02:24

标签: java hibernate hibernate-mapping

我想插入一个包含两个归档名称organization_id和account_id的行,该行是从同一个表(组织表)中引用的。

EntityModel.java

@ManyToOne
@JoinColumn(name = "organization_id")
private OrganizationModel organization;

@ManyToOne
@JoinColumn(name = "account_id")
private OrganizationModel account;

OrganizationModel.java

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "organization_id", unique = true, nullable = false)
private int organizationId;

@OneToMany(mappedBy = "organization")
private Set<EntityModel> organization;

但是我得到了以下错误。

Repeated column in mapping for entity: com.party.OrganizationModel column: organization_id (should be mapped with insert="false" update="false")

当我为帐户添加insert="false" update="false"时,错误消失了。但我需要同时插入帐户和组织。

1 个答案:

答案 0 :(得分:0)

为EntityModel添加主键。

以下代码对我有用:

    class call_methods():


    def _method1(self,context):

        print "Now call method 2";  

        this._method2(context);

        print "Finish"; 

        return {}


    def _method2(self, context={}):

        print "method 2 called"


        return {}