Repeated column in mapping for entity error when join column is already defined with updatable = false,...











up vote
0
down vote

favorite












So I know this question has been posted before, but I can't seem to find the solution.



So I have the below 3 classes to create a one to many relationship between person and address with an additional column on the join table.



 @Entity
@Table(name="person")
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "personAddressId.person")
private List<PersonAddress> addresses;

public Integer getId() {
return id;
}

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

public List<PersonAddress> getAddresses() {
if(addresses == null)
addresses = new ArrayList<>();
return addresses;
}

public void setAddresses(List<PersonAddress> addresses) {
this.addresses = addresses;
}

}

@Entity
@Table(name = "person_address")
@AssociationOverrides( {
@AssociationOverride(name="personAddressId.person", joinColumns =
@JoinColumn(name="person_id")),
@AssociationOverride(name="personAddressId.address", joinColumns =
@JoinColumn(name = "address_id", updatable = false, insertable = false))
})
public class PersonAddress {
private PersonAddressId personAddressId;

private String address_type;

@EmbeddedId
public PersonAddressId getPersonAddressId() {
return personAddressId;
}

public void setPersonAddressId(PersonAddressId personAddressId) {
this.personAddressId = personAddressId;
}

@Transient
public Person getPerson() {return personAddressId.getPerson();}

public void setPerson(Person person) {personAddressId.setPerson(person);}

@Transient
public Address getAddress() {return personAddressId.getAddress();}

public void setAddress(Address address) {personAddressId.setAddress(address);}

@Transient
public Integer getAddress_id() {return personAddressId.getAddress_id();}

public void setAddress_id(Integer address_id) {personAddressId.setAddress_id(address_id);}

public String getAddress_type() {
return address_type;
}

public void setAddress_type(String address_type) {
this.address_type = address_type;
}
}

@Embeddable
public class PersonAddressId implements Serializable {
private Person person;
private Address address;
private Integer address_id;

@ManyToOne
public Person getPerson() {return person;}

public void setPerson(Person person) {this.person = person;}

@ManyToOne
public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

@Column(name="address_id")
public Integer getAddress_id() {
return address_id;
}

public void setAddress_id(Integer address_id) {
this.address_id = address_id;
}


}



As you can see I do set updateable = false, insertable = false on the association override join definition for address. But hibernate keeps throwing the error




Caused by: org.hibernate.MappingException: Repeated column in mapping
for entity: com.operations.Core.Entities.PersonAddress column:
address_id (should be mapped with insert="false" update="false")




I've tried looking up the solution but all the solutions say to add updateable = false, insertable = false which I've already done. I'm pretty new to hibernate so I don't know if I'm missing something, but any help would be appreciated.
I'm trying to use Address_id instead of the full Address entity to create the association between Person and Address to save myself an unnecessary get to the address table.



I've tried moving the association override to the getters directly, but it still throws the same error.










share|improve this question
























  • Why do you have Address and address_id in your embedded key. Seems like they are creating the same field names.
    – K.Nicholas
    Nov 20 at 3:54










  • Because I wanted to create the relationship by just providing the foreign key of the address instead of the full address object. From everything I'm reading it says to create an entity and a fk property both with the same column name then mark one as update = false, insert = false. Which is what I feel like i did, but it's still not working. stackoverflow.com/questions/6311776/….
    – Gloria
    Nov 20 at 15:37

















up vote
0
down vote

favorite












So I know this question has been posted before, but I can't seem to find the solution.



So I have the below 3 classes to create a one to many relationship between person and address with an additional column on the join table.



 @Entity
@Table(name="person")
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "personAddressId.person")
private List<PersonAddress> addresses;

public Integer getId() {
return id;
}

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

public List<PersonAddress> getAddresses() {
if(addresses == null)
addresses = new ArrayList<>();
return addresses;
}

public void setAddresses(List<PersonAddress> addresses) {
this.addresses = addresses;
}

}

@Entity
@Table(name = "person_address")
@AssociationOverrides( {
@AssociationOverride(name="personAddressId.person", joinColumns =
@JoinColumn(name="person_id")),
@AssociationOverride(name="personAddressId.address", joinColumns =
@JoinColumn(name = "address_id", updatable = false, insertable = false))
})
public class PersonAddress {
private PersonAddressId personAddressId;

private String address_type;

@EmbeddedId
public PersonAddressId getPersonAddressId() {
return personAddressId;
}

public void setPersonAddressId(PersonAddressId personAddressId) {
this.personAddressId = personAddressId;
}

@Transient
public Person getPerson() {return personAddressId.getPerson();}

public void setPerson(Person person) {personAddressId.setPerson(person);}

@Transient
public Address getAddress() {return personAddressId.getAddress();}

public void setAddress(Address address) {personAddressId.setAddress(address);}

@Transient
public Integer getAddress_id() {return personAddressId.getAddress_id();}

public void setAddress_id(Integer address_id) {personAddressId.setAddress_id(address_id);}

public String getAddress_type() {
return address_type;
}

public void setAddress_type(String address_type) {
this.address_type = address_type;
}
}

@Embeddable
public class PersonAddressId implements Serializable {
private Person person;
private Address address;
private Integer address_id;

@ManyToOne
public Person getPerson() {return person;}

public void setPerson(Person person) {this.person = person;}

@ManyToOne
public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

@Column(name="address_id")
public Integer getAddress_id() {
return address_id;
}

public void setAddress_id(Integer address_id) {
this.address_id = address_id;
}


}



As you can see I do set updateable = false, insertable = false on the association override join definition for address. But hibernate keeps throwing the error




Caused by: org.hibernate.MappingException: Repeated column in mapping
for entity: com.operations.Core.Entities.PersonAddress column:
address_id (should be mapped with insert="false" update="false")




I've tried looking up the solution but all the solutions say to add updateable = false, insertable = false which I've already done. I'm pretty new to hibernate so I don't know if I'm missing something, but any help would be appreciated.
I'm trying to use Address_id instead of the full Address entity to create the association between Person and Address to save myself an unnecessary get to the address table.



I've tried moving the association override to the getters directly, but it still throws the same error.










share|improve this question
























  • Why do you have Address and address_id in your embedded key. Seems like they are creating the same field names.
    – K.Nicholas
    Nov 20 at 3:54










  • Because I wanted to create the relationship by just providing the foreign key of the address instead of the full address object. From everything I'm reading it says to create an entity and a fk property both with the same column name then mark one as update = false, insert = false. Which is what I feel like i did, but it's still not working. stackoverflow.com/questions/6311776/….
    – Gloria
    Nov 20 at 15:37















up vote
0
down vote

favorite









up vote
0
down vote

favorite











So I know this question has been posted before, but I can't seem to find the solution.



So I have the below 3 classes to create a one to many relationship between person and address with an additional column on the join table.



 @Entity
@Table(name="person")
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "personAddressId.person")
private List<PersonAddress> addresses;

public Integer getId() {
return id;
}

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

public List<PersonAddress> getAddresses() {
if(addresses == null)
addresses = new ArrayList<>();
return addresses;
}

public void setAddresses(List<PersonAddress> addresses) {
this.addresses = addresses;
}

}

@Entity
@Table(name = "person_address")
@AssociationOverrides( {
@AssociationOverride(name="personAddressId.person", joinColumns =
@JoinColumn(name="person_id")),
@AssociationOverride(name="personAddressId.address", joinColumns =
@JoinColumn(name = "address_id", updatable = false, insertable = false))
})
public class PersonAddress {
private PersonAddressId personAddressId;

private String address_type;

@EmbeddedId
public PersonAddressId getPersonAddressId() {
return personAddressId;
}

public void setPersonAddressId(PersonAddressId personAddressId) {
this.personAddressId = personAddressId;
}

@Transient
public Person getPerson() {return personAddressId.getPerson();}

public void setPerson(Person person) {personAddressId.setPerson(person);}

@Transient
public Address getAddress() {return personAddressId.getAddress();}

public void setAddress(Address address) {personAddressId.setAddress(address);}

@Transient
public Integer getAddress_id() {return personAddressId.getAddress_id();}

public void setAddress_id(Integer address_id) {personAddressId.setAddress_id(address_id);}

public String getAddress_type() {
return address_type;
}

public void setAddress_type(String address_type) {
this.address_type = address_type;
}
}

@Embeddable
public class PersonAddressId implements Serializable {
private Person person;
private Address address;
private Integer address_id;

@ManyToOne
public Person getPerson() {return person;}

public void setPerson(Person person) {this.person = person;}

@ManyToOne
public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

@Column(name="address_id")
public Integer getAddress_id() {
return address_id;
}

public void setAddress_id(Integer address_id) {
this.address_id = address_id;
}


}



As you can see I do set updateable = false, insertable = false on the association override join definition for address. But hibernate keeps throwing the error




Caused by: org.hibernate.MappingException: Repeated column in mapping
for entity: com.operations.Core.Entities.PersonAddress column:
address_id (should be mapped with insert="false" update="false")




I've tried looking up the solution but all the solutions say to add updateable = false, insertable = false which I've already done. I'm pretty new to hibernate so I don't know if I'm missing something, but any help would be appreciated.
I'm trying to use Address_id instead of the full Address entity to create the association between Person and Address to save myself an unnecessary get to the address table.



I've tried moving the association override to the getters directly, but it still throws the same error.










share|improve this question















So I know this question has been posted before, but I can't seem to find the solution.



So I have the below 3 classes to create a one to many relationship between person and address with an additional column on the join table.



 @Entity
@Table(name="person")
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "personAddressId.person")
private List<PersonAddress> addresses;

public Integer getId() {
return id;
}

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

public List<PersonAddress> getAddresses() {
if(addresses == null)
addresses = new ArrayList<>();
return addresses;
}

public void setAddresses(List<PersonAddress> addresses) {
this.addresses = addresses;
}

}

@Entity
@Table(name = "person_address")
@AssociationOverrides( {
@AssociationOverride(name="personAddressId.person", joinColumns =
@JoinColumn(name="person_id")),
@AssociationOverride(name="personAddressId.address", joinColumns =
@JoinColumn(name = "address_id", updatable = false, insertable = false))
})
public class PersonAddress {
private PersonAddressId personAddressId;

private String address_type;

@EmbeddedId
public PersonAddressId getPersonAddressId() {
return personAddressId;
}

public void setPersonAddressId(PersonAddressId personAddressId) {
this.personAddressId = personAddressId;
}

@Transient
public Person getPerson() {return personAddressId.getPerson();}

public void setPerson(Person person) {personAddressId.setPerson(person);}

@Transient
public Address getAddress() {return personAddressId.getAddress();}

public void setAddress(Address address) {personAddressId.setAddress(address);}

@Transient
public Integer getAddress_id() {return personAddressId.getAddress_id();}

public void setAddress_id(Integer address_id) {personAddressId.setAddress_id(address_id);}

public String getAddress_type() {
return address_type;
}

public void setAddress_type(String address_type) {
this.address_type = address_type;
}
}

@Embeddable
public class PersonAddressId implements Serializable {
private Person person;
private Address address;
private Integer address_id;

@ManyToOne
public Person getPerson() {return person;}

public void setPerson(Person person) {this.person = person;}

@ManyToOne
public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

@Column(name="address_id")
public Integer getAddress_id() {
return address_id;
}

public void setAddress_id(Integer address_id) {
this.address_id = address_id;
}


}



As you can see I do set updateable = false, insertable = false on the association override join definition for address. But hibernate keeps throwing the error




Caused by: org.hibernate.MappingException: Repeated column in mapping
for entity: com.operations.Core.Entities.PersonAddress column:
address_id (should be mapped with insert="false" update="false")




I've tried looking up the solution but all the solutions say to add updateable = false, insertable = false which I've already done. I'm pretty new to hibernate so I don't know if I'm missing something, but any help would be appreciated.
I'm trying to use Address_id instead of the full Address entity to create the association between Person and Address to save myself an unnecessary get to the address table.



I've tried moving the association override to the getters directly, but it still throws the same error.







java hibernate jpa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 0:15

























asked Nov 20 at 0:10









Gloria

363




363












  • Why do you have Address and address_id in your embedded key. Seems like they are creating the same field names.
    – K.Nicholas
    Nov 20 at 3:54










  • Because I wanted to create the relationship by just providing the foreign key of the address instead of the full address object. From everything I'm reading it says to create an entity and a fk property both with the same column name then mark one as update = false, insert = false. Which is what I feel like i did, but it's still not working. stackoverflow.com/questions/6311776/….
    – Gloria
    Nov 20 at 15:37




















  • Why do you have Address and address_id in your embedded key. Seems like they are creating the same field names.
    – K.Nicholas
    Nov 20 at 3:54










  • Because I wanted to create the relationship by just providing the foreign key of the address instead of the full address object. From everything I'm reading it says to create an entity and a fk property both with the same column name then mark one as update = false, insert = false. Which is what I feel like i did, but it's still not working. stackoverflow.com/questions/6311776/….
    – Gloria
    Nov 20 at 15:37


















Why do you have Address and address_id in your embedded key. Seems like they are creating the same field names.
– K.Nicholas
Nov 20 at 3:54




Why do you have Address and address_id in your embedded key. Seems like they are creating the same field names.
– K.Nicholas
Nov 20 at 3:54












Because I wanted to create the relationship by just providing the foreign key of the address instead of the full address object. From everything I'm reading it says to create an entity and a fk property both with the same column name then mark one as update = false, insert = false. Which is what I feel like i did, but it's still not working. stackoverflow.com/questions/6311776/….
– Gloria
Nov 20 at 15:37






Because I wanted to create the relationship by just providing the foreign key of the address instead of the full address object. From everything I'm reading it says to create an entity and a fk property both with the same column name then mark one as update = false, insert = false. Which is what I feel like i did, but it's still not working. stackoverflow.com/questions/6311776/….
– Gloria
Nov 20 at 15:37



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384421%2frepeated-column-in-mapping-for-entity-error-when-join-column-is-already-defined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384421%2frepeated-column-in-mapping-for-entity-error-when-join-column-is-already-defined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin