I have decided to use JPA Annotations instead of hbm.xml files because otherwise i can not use Envers and now i ran into a problem.
I have the following mappings:
Code:
@javax.persistence.Entity
@Table(name = "entity_action")
public class EntityAction implements java.io.Serializable {
private EntityActionId id;
private Map<Locale, LocalizedEntityAction> localized = new HashMap<Locale, LocalizedEntityAction>(
0);
private Picture picture;
public EntityAction() {
}
public EntityAction(EntityActionId id) {
this.id = id;
}
public EntityAction(EntityActionId id, Picture picture) {
this.id = id;
this.picture = picture;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "name", column =
@Column(name = "enac_name", nullable = false, length = 60)),
//@AttributeOverride(name = "entityModuleId", column = @Column(name = "enac_module_id", nullable = false)),
@AttributeOverride(name = "entityClass", column =
@Column(name = "enac_entity_class", nullable = false))})
public EntityActionId getId() {
return id;
}
public void setId(EntityActionId id) {
this.id = id;
}
@ElementCollection
@CollectionTable(name = "localized_entity_action", joinColumns = {
@JoinColumn(name = "loenac_entity_class", referencedColumnName = "enac_entity_class"),
@JoinColumn(name = "loenac_website_webs_id", referencedColumnName = "enac_website_webs_id"),
@JoinColumn(name = "loenac_name", referencedColumnName = "enac_name")})
@MapKeyJoinColumn(name = "loenac_locale")
public Map<Locale, LocalizedEntityAction> getLocalized() {
return this.localized;
}
public void setLocalized(Map<Locale, LocalizedEntityAction> localized) {
this.localized = localized;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "enac_picture_pict_id")
public Picture getPicture() {
return this.picture;
}
public void setPicture(Picture picture) {
this.picture = picture;
}
public boolean equals(Object other) {
if ((this == other)) {
return true;
}
if ((other == null)) {
return false;
}
if (!(other instanceof EntityAction)) {
return false;
}
EntityAction castOther = (EntityAction) other;
return ((this.getId().equals(castOther.getId())) || (this.getId() != null
&& castOther.getId() != null && this.getId().equals(
castOther.getId())));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getId() == null ? 0 : this.getId().hashCode());
return result;
}
}
@Embeddable
public class EntityActionId {
private String name;
private Entity entity;
public EntityActionId() {
}
public EntityActionId(String name, Entity entity) {
this.name = name;
this.entity = entity;
}
@Column(name = "enac_name", nullable = false, length = 60)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "enac_entity_class", referencedColumnName = "enti_entity_class", nullable = false),
@JoinColumn(name = "enac_website_webs_id", referencedColumnName = "enti_website_webs_id", nullable = false)})
public Entity getEntity() {
return this.entity;
}
public void setEntity(Entity entity) {
this.entity = entity;
}
@Override
public boolean equals(Object other) {
if ((this == other)) {
return true;
}
if ((other == null)) {
return false;
}
if (!(other instanceof EntityActionId)) {
return false;
}
EntityActionId castOther = (EntityActionId) other;
if ((this.getName() == null) ? (castOther.getName() != null) : !this.getName().equals(castOther.getName())) {
return false;
}
if (this.getEntity() != castOther.getEntity() && (this.getEntity() == null || !this.getEntity().equals(castOther.getEntity()))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 97 * hash + (this.getName() != null ? this.getName().hashCode() : 0);
hash = 97 * hash + (this.getEntity() != null ? this.getEntity().hashCode() : 0);
return hash;
}
}
When i want to build a EntityManagerFactory i get the following error Message:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.blazebit.web.cms.core.model.EntityAction column: enac_entity_class (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:676)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:698)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:720)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:474)
at org.hibernate.mapping.RootClass.validate(RootClass.java:235)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1362)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
... 5 more
What is the reason for the message? I have already tried to use insertable=false, updateable=false on every definition of the column and i still got the message!
I am really desperated and don't know what else I could try! Please help me!