-->
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: Wrong query generated with @OrderBy annotation
PostPosted: Sun Oct 17, 2010 12:45 pm 
Newbie

Joined: Sun Oct 17, 2010 12:38 pm
Posts: 1
Hi,

I am using Hibernate3 and i have an entity with the following collection:
Code:
@ManyToMany(fetch=FetchType.LAZY,cascade = { CascadeType.MERGE, CascadeType.PERSIST})
   @JoinTable(name = "buys_publishers", joinColumns=@JoinColumn(name="buy_id", referencedColumnName = "buy_id"), inverseJoinColumns=@JoinColumn(name = "publisher_id", referencedColumnName = "publisher_id"))
   @OrderBy("name")
   private List<Publisher> publishers;


The target entity (Publisher) inherits from an entity that holds the "name" attribute on which the @orderby is activated.

here is the target entity:
Code:
@Entity
@Table(name="publishers")
@PrimaryKeyJoinColumn(name="account_id")
public class Publisher extends Account{
   
   /**
    *
    */
   private static final long serialVersionUID = 1L;
   
   @Column(name = "publisher_id")
   private Long publisherId;
   
   public Long getPublisherId() {
      return publisherId;
   }

   public void setPublisherId(Long publisherId) {
      this.publisherId = publisherId;
   }
   

}


and the super class:
Code:
@Entity
@Table(name="accounts")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Account implements Serializable{
   
   /**
    *
    */
   private static final long serialVersionUID = 1L;

   
   @Id
   @Column(name="id",unique=true, nullable=false )
   @GeneratedValue( strategy = IDENTITY )
   private long id;
   
   @Column(name = "name")
   private String name;
   
   @Column(name = "account_type")
   @Enumerated(EnumType.ORDINAL)
   private AccountType accountType;

   public long getId() {
      return id;
   }

   public void setId(long id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public AccountType getAccountType() {
      return accountType;
   }

   public void setAccountType(AccountType accountType) {
      this.accountType = accountType;
   }

}


the query that Hibernate generates is:
Code:
select publishers0_.buy_id as buy1_1_, publishers0_.publisher_id as publisher2_1_, publisher1_.account_id as id6_0_, publisher1_1_.account_type as account2_6_0_, publisher1_1_.name as name6_0_, publisher1_.publisher_id as publisher1_18_0_ from buys_publishers publishers0_ left outer join publishers publisher1_ on publishers0_.publisher_id=publisher1_.publisher_id left outer join accounts publisher1_1_ on publisher1_.account_id=publisher1_1_.id where publishers0_.buy_id=? order by accounts.name asc


it is clear from the query that the order by should be on publisher1_1_, am i doing something wrong or is this a bug?

Thank you.


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.