Menu

#20 Inheritance does not generate code what compiles

taylor-mda
open
nobody
5
2008-03-17
2008-03-17
mark2000
No

Child is trying to reference a private field of the parent

Entity1:

@Generated
@Id
property Long id

Entity2:

property String name

Entity2 extends Entity1

The generated code for property id in Entity1.java

/**
* null
* @generated
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
/** @generated */
public void setId(final Long id) {
this.id = id;
}

/** @generated */
private Long id = null;

The generated code for property hashCode and equals in Entity2.java

/** @generated */
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((id == null) ? 0 : id.hashCode());
return result;
}

/** @generated */
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Interface other = (Interface) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}

The problem that the id is a private field, but should be a protected field... I tried to change it in the model to a protected field but that had no result.

Discussion


Log in to post a comment.