[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Use an entity as a discriminator column
|
The column must be in the table, you should use "service_type_id" not
"service_type_id.id".
bea-5 wrote:
>
> Hy,
>
> The question is that the discriminator value is the column name in other
> entity. So, the next sample is incorrect, but I'd like to get something
> like
> this:
>
> @Entity
> @Inheritance(strategy = InheritanceType.JOINED)
> @DiscriminatorColumn(name = "service_type_id.id")
> .....
> @JoinColumn(name = "service_type_id", referencedColumnName = "id")
> @ManyToOne
> private ServiceType serviceTypeId;
>
>
> But I get the excpention:
> MySQLSyntaxErrorException: Unknow column 'TipoServicio.id' in 'field
> list'.
>
> which is quite logical. I'd like to know if there is a way to do what I
> want.
> Anyway, I can try to avoid using the mapped attribute as the
> discriminator.
>
> Thanks!
>
>
>
> On Mon, Nov 30, 2009 at 9:31 PM, James Sutherland
> <jamesssss@xxxxxxxxx>wrote:
>
>>
>> In general I would avoid using a mapped attribute as the discriminator,
>> as
>> attribute value can change, but an object's class cannot. But I don't
>> see
>> any reason why it wouldn't work, did you try it, what error do you get?
>>
>> The discriminator value is just the column value, so integer id, 1, 2, 3,
>> etc.
>> You may need to make the JoinColumn as insertable/updateable=false.
>>
>>
>>
>> bea-5 wrote:
>> >
>> > Hi,
>> >
>> > I have some entities with an joined inheritance type. In my root entity
>> I
>> > have an attribute that is a @ManyToOne relationship to other table. In
>> > short, my entity looks like this:
>> >
>> > @Entity
>> > @Inheritance(strategy = InheritanceType.JOINED)
>> > @Table(name = "service")
>> > public class Service implements Serializable {
>> >
>> > @JoinColumn(name = "service_type_id", referencedColumnName = "id")
>> > @ManyToOne
>> > private ServiceType serviceTypeId;
>> > ....
>> >
>> > The attribute serviceTypeId is a foreign key to other entity:
>> >
>> > @Entity
>> > @Table(name = "service_type")
>> > public class TipoServicio implements Serializable {
>> >
>> > @Id
>> > @GeneratedValue(strategy = GenerationType.IDENTITY)
>> > @Basic(optional = false)
>> > @Column(name = "id")
>> > private Integer id;
>> >
>> > @Column(name = "name")
>> > private String name;
>> > ......
>> >
>> > I'd like to have as DiscriminatorColumn the field serviceTypeId, but I
>> > don't
>> > know how to do it, as that field hasn't a correct discriminatorType. Is
>> > there any way to do what I want?
>> >
>> > Thanks!
>> >
>> > --
>> > Beatriz Nombela Escobar
>> > beaotx@xxxxxxxxx
>> >
>
-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://old.nabble.com/Use-an-entity-as-a-discriminator-column-tp26542136p26694694.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.