i have a composite id defined on my class structure as below. Unfortunatly i always get a hibernate error that complains on the not found "part2":
"Property of @IdClass not found in entity MoreClass : part2"
Can anybody help me on fixing the problem? (or at least point me on a helpful jpa/hibernate doc?)
@IdClass(ClassKey.class)
@Entity
public class MoreClass extends LessClass implements Serializable
{
@Id
String part1;
}
@MappedSuperclass
public class LessClass implements Serializable
{
@Id
String part2;
}
public class ClassKey implements Serializable
{
String part1;
String part2;
}
The mentioned workaround for HHH-9114 bug by Michael works, e.g. in my case by adding to
TwitterListedCount
: (note that both@Id
and@Type
must be added for user types to still work)BTW, the workaround has a nasty side-effect HHH-9350 when used with schema generation, it generates duplicate composite columns:
I tried to not use
@MappedSuperclass
at all, but the wrong schema generation still happens. BTW I'm usingDefaultComponentSafeNamingStrategy
which may be where the bug lies. This is probably a different bug, asked in Hibernate find with composite key. Invalid column name ExceptionThe proper workaround involves adding
@Column(name=)
manually, which works well with schema generation:FYI, when used together with Spring Data JPA, it's required to remove the
@Id
and@Type
annotations from theMappedSuperclass
. If these are not removed, there will be errors bellow. It doesn't change the nature of this Hibernate bug, BTW.Actually bumped into the
same problem
.As:
Does seem to work, I would deem it a bug. See https://hibernate.atlassian.net/browse/HHH-9114.
From the JPA spec:
So according to JPA you can't redefine the
@Id
. I wouldn't call this a bug.Although the workaround given as answer here might work, it may happen that for other JPA frameworks it doesn't work.