Issues

Select view

Select search mode

 

Embeddable ManyToOne generation is not correct

Description

An attribute that is a foreign key plus part of a primary key is not generated correctly in java:

 

package net.osgiliath.datamigrator.archetype.carmamigrator.domain; // Generated 20 juin 2024, 17:48:14 by Hibernate Tools 6.4.4.Final import jakarta.persistence.AttributeOverride; import jakarta.persistence.AttributeOverrides; import jakarta.persistence.Column; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; /** * AccessGroupsCustomData generated by hbm2java */ @Entity @Table(name="ACCESS_GROUPS_CUSTOM_DATA" ) public class AccessGroupsCustomData implements java.io.Serializable { private AccessGroupsCustomDataId id; private AccessGroups accessGroups; private String propValue; public AccessGroupsCustomData() { } public AccessGroupsCustomData(AccessGroupsCustomDataId id, AccessGroups accessGroups) { this.id = id; this.accessGroups = accessGroups; } public AccessGroupsCustomData(AccessGroupsCustomDataId id, AccessGroups accessGroups, String propValue) { this.id = id; this.accessGroups = accessGroups; this.propValue = propValue; } @EmbeddedId @AttributeOverrides( { @AttributeOverride(name="groupId", column=@Column(name="GROUP_ID", precision=19, scale=0) ), @AttributeOverride(name="propKey", column=@Column(name="PROP_KEY", length=255) ) } ) public AccessGroupsCustomDataId getId() { return this.id; } public void setId(AccessGroupsCustomDataId id) { this.id = id; } @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="GROUP_ID") public AccessGroups getAccessGroups() { return this.accessGroups; } public void setAccessGroups(AccessGroups accessGroups) { this.accessGroups = accessGroups; } @Column(name="PROP_VALUE", length=2048) public String getPropValue() { return this.propValue; } public void setPropValue(String propValue) { this.propValue = propValue; } } package net.osgiliath.datamigrator.archetype.carmamigrator.domain; // Generated 20 juin 2024, 17:48:14 by Hibernate Tools 6.4.4.Final import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import java.math.BigInteger; /** * AccessGroupsCustomDataId generated by hbm2java */ @Embeddable public class AccessGroupsCustomDataId implements java.io.Serializable { private BigInteger groupId; private String propKey; public AccessGroupsCustomDataId() { } public AccessGroupsCustomDataId(BigInteger groupId, String propKey) { this.groupId = groupId; this.propKey = propKey; } @Column(name="GROUP_ID", precision=19, scale=0) public BigInteger getGroupId() { return this.groupId; } public void setGroupId(BigInteger groupId) { this.groupId = groupId; } @Column(name="PROP_KEY", length=255) public String getPropKey() { return this.propKey; } public void setPropKey(String propKey) { this.propKey = propKey; } public boolean equals(Object other) { if ( (this == other ) ) return true; if ( (other == null ) ) return false; if ( !(other instanceof AccessGroupsCustomDataId) ) return false; AccessGroupsCustomDataId castOther = ( AccessGroupsCustomDataId ) other; return ( (this.getGroupId()==castOther.getGroupId()) || ( this.getGroupId()!=null && castOther.getGroupId()!=null && this.getGroupId().equals(castOther.getGroupId()) ) ) && ( (this.getPropKey()==castOther.getPropKey()) || ( this.getPropKey()!=null && castOther.getPropKey()!=null && this.getPropKey().equals(castOther.getPropKey()) ) ); } public int hashCode() { int result = 17; result = 37 * result + ( getGroupId() == null ? 0 : this.getGroupId().hashCode() ); result = 37 * result + ( getPropKey() == null ? 0 : this.getPropKey().hashCode() ); return result; } }

 

Which fails because there are two fields representing the GROUP_ID` column

Environment

None

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

CharlieM

Community Help Wanted

Yes, please

Components

Affects versions

Priority

Created June 20, 2024 at 4:39 PM
Updated December 13, 2024 at 3:09 PM

Activity

Show:

CharlieM June 24, 2024 at 11:38 AM

In order to fix the bad behavior, this statement

@ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="GROUP_ID") public AccessGroups getAccessGroups() {

Should be replaced by

@ManyToOne(fetch=FetchType.LAZY) @MapsId("groupId") @JoinColumn(name="GROUP_ID") public AccessGroups getAccessGroups() {