-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Multiple properties to single column with inheritance
PostPosted: Thu Jul 12, 2012 12:12 pm 
Newbie

Joined: Thu Apr 16, 2009 5:20 am
Posts: 2
Hi,

I have previously mapped two separate properties within one class to the same column, and just need to set "insertable = false, updatable = false" on one of those properties that is read only.

I now have a class called Script that inherits from class Item of which I want a property that uses the column from the parent class (and table) that is already mapped in the parent class.

Code:
@Entity()
@Table(name = "Item")
public class Item {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int itemId;

    @ManyToOne(fetch = FetchType.LAZY, optional = true, targetEntity = Item.class)   
    @JoinColumn(referencedColumnName = "itemId")
    private Item parent;
}

@Entity()
@Table(name = "Script")
@Inheritance(strategy = InheritanceType.JOINED)
public class Script extends Item{

    @ManyToOne(fetch = FetchType.LAZY, optional = true, targetEntity = Packet.class)
    @JoinColumn(name = "parent_itemid", insertable = false, updatable = false)
    private Packet packet;

}


Here I need Script.packet to be mapped to the same column as parent in the Item class (so parent_itemid in the Item table).

Any ideas if this is possible and how I would manage to code this?

At the moment it fails because the SQL generated expects parent_itemid to be on the Script table.

Any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: Multiple properties to single column with inheritance
PostPosted: Fri Jul 13, 2012 9:41 am 
Newbie

Joined: Thu Apr 16, 2009 5:20 am
Posts: 2
I have figured out a way of doing what I wanted to do using DetachedCriteria, Projections.id() and Subqueries.propertyIn


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.