2

I'm working on spring mvc and creating a one to many relationship between 2 tables. I have 2 models:

  1. ContractHeader 1:many
  2. ContractEntitlement many:1

ContractHeader.java

@Entity
@Table(name = "CONTRACT_HEADER")
public class ContractHeader {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @OneToMany(mappedBy = "contractHeader", cascade = CascadeType.ALL)
    private List<ContractEntitlement> contractEntitlements;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    public List<ContractEntitlement> getContractEntitlements() {
        return contractEntitlements;
    }

    public void setContractEntitlements(List<ContractEntitlement> contractEntitlements) {
        this.contractEntitlements = contractEntitlements;
    }

}

ContractEntitlement.java

@Entity
@Table(name = "CONTRACT_ENTITLEMENT")
public class ContractEntitlement {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @ManyToOne
    @JoinColumn(name = "id")
    private ContractHeader contractHeader; 

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public ContractHeader getContractHeader() {
        return contractHeader;
    }

    public void setContractHeader(ContractHeader contractHeader) {
        this.contractHeader = contractHeader;
    }

}

I'm getting an error when publishing in eclipse sts:

deploy is failing=Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.hibernate.MappingException: Repeated column in mapping for entity: com.at.ccts.model.ContractEntitlement column: id (should be mapped with insert="false" update="false"). Please see server.log for more details.

Any ideas?

1
  • See server.log for more details? Commented Apr 29, 2017 at 17:21

2 Answers 2

1

In your entity ContractHeader your mapping will give a table with two columns with name id ,change the name attribute in the @JoinColumn

@ManyToOne
@JoinColumn(name = "idContractHeader")
private ContractHeader contractHeader; 
Sign up to request clarification or add additional context in comments.

Comments

0

you should use as link this:-

@OneToMany(mappedBy = "ContractHeader", cascade = CascadeType.ALL)
private List<ContractEntitlement> contractEntitlements;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.