[jboss-user] [EJB 3.0] - EJB QL/ JPQL and search for inheritance

jrosskopf do-not-reply at jboss.com
Wed Dec 6 07:10:01 EST 2006


Hello,

I have a problem with creating a QL expression for some of my entities. First of all I have an entity "Item" which has a ManyToMany reference to 0..* "Tags" But Tag is just a base class for more complex Entities such as "PlaceMark"


  | @Entity
  | public class Item implements Serializable{
  | 	private static final long serialVersionUID = -6240744395949853067L;
  |  . 
  |  .
  |  .
  |         /**
  | 	 *  Get a list of tags associated with the item
  | 	 * @return list of tags associated with the item
  | 	 */
  | 	@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})
  | 	public List<Tag> getTags() {
  | 		return tags;
  | 	}
  | 	public void setTags(List<Tag> tags) {
  | 		this.tags = tags;
  | 	}
  | }
  | 


  | @Entity
  | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  | @DiscriminatorColumn(name="dtype", discriminatorType=DiscriminatorType.STRING)
  | @DiscriminatorValue("Tag")
  | public class Tag implements Serializable{
  | 	private static final long serialVersionUID = 2432906233376577675L;
  | 
  | 	long gid;
  | 	String name;
  | 	List<Item> items;
  | 
  | 	@Id
  | 	@GeneratedValue
  | 	public long getGid() {
  | 		return gid;
  | 	}
  | 	public void setGid(long gid) {
  | 		this.gid = gid;
  | 	}
  | 
  | 	public String getName() {
  | 		return name;
  | 	}
  | 	public void setName(String value) {
  | 		this.name = value;
  | 	}
  | 
  | 	@ManyToMany(mappedBy="tags", cascade={CascadeType.PERSIST, CascadeType.MERGE})
  | 	public List<Item> getItems() {
  | 		return items;
  | 	}
  | 	public void setItems(List<Item> items) {
  | 		this.items = items;
  | 	}
  | }
  | 


  | @Entity
  | @DiscriminatorValue("PlaceMark")
  | public class PlaceMark extends Tag implements Serializable {
  | 	private static final long serialVersionUID = -6646702308712255267L;
  | 
  | 	boolean visibibilty;
  | 	LookAt lookAt;
  | 	Point point;
  | 
  | 	public PlaceMark() {
  | 		super.setName("PlaceMark");
  | 	}
  | 
  | 	@Embedded
  | 	public LookAt getLookAt() {
  | 		return lookAt;
  | 	}
  | 	public void setLookAt(LookAt lookAt) {
  | 		this.lookAt = lookAt;
  | 	}
  | 
  | 	@Embedded()
  | 	public Point getPoint() {
  | 		return point;
  | 	}
  | 	public void setPoint(Point point) {
  | 		this.point = point;
  | 	}
  | 
  | 	public boolean isVisibibilty() {
  | 		return visibibilty;
  | 	}
  | 	public void setVisibibilty(boolean visibibilty) {
  | 		this.visibibilty = visibibilty;
  | 	}
  | 
  | 	public void setName(String value) {
  | 	}
  | 
  | }
  | 

So now my question, how can I search for items annotaded with different types of tags in the "Tag" class hierachy?

Thank you in advance.
Regards
---
Joachim

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3991610#3991610

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3991610



More information about the jboss-user mailing list