-->
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.  [ 1 post ] 
Author Message
 Post subject: add namedquery using annotation to library class
PostPosted: Thu Jan 31, 2013 1:00 pm 
Newbie

Joined: Thu Dec 23, 2004 6:08 am
Posts: 4
I have an entity, say Customer, that comes in a library and I cannot change. I would like to add a NamedQuery to this entity using annotation. My first trial is to subclass the entity class and add a NamedQuery to the annotation of the subclass, but that does not work because hibernate requires a discriminator column in the table. I later find a solution by not using subclass, but just to map a separate entity to the table, like this:

@Entity
@Table(name = "CUSTOMER")
@NamedQueries({
@NamedQuery(name = "MY_CUSTOMER_QUERY" ,
query = "SELECT name from Customer " +
"WHERE id in (:ids) order by name")
})
public class MyCustomer {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"CUSTOMER_SEQ")
@SequenceGenerator(name = "CUSTOMER_SEQ", sequenceName = "CUSTOMER_SEQ",
allocationSize = 1)
@Column(name = "CUSTOMER_ID")
private Long id;
}

While this appears to work, it does requires specifying a table and an id for the code to work, which is not really used. I wonder if there is a simpler way to do this?


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

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.