-->
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.  [ 3 posts ] 
Author Message
 Post subject: inheritance error?
PostPosted: Fri Jan 25, 2008 10:04 am 
Newbie

Joined: Wed Dec 05, 2007 7:03 am
Posts: 2
Hello, we have a serious problem in our system.

the problem is with two class, lets call them Users, and Planner. Planner extends Users, with joined inheritance strategy.

when i run the following hql query:

Code:
      Query query = HibernateSessionFactory.getInstance()
                  .getCurrentSession().createQuery(
                        "from Users where username=:username").setString(
                        "username", username);

      Users u = (Users) query.uniqueResult();


The problem is that in the test environment, this query does not return the SuperUser, even though the records exist in the database, and in the developer environment it works fine.

We failed to reproduce this problem in the developer environment, not even when we connected to the same database. There are no errors in the log.


we are using Hibernate 3.2.0.cr4, Tomcat 5.0, the only difference seems to be that the application server runs on a windows xp on the developer environment, and on a suse linux in the test environment.
The database is a Oracle 9.2.0.6.


the sql generated:

Code:
select users0_.ID as ID5_, users0_.version as version5_, users0_.NAME as NAME5_, users0_.USERNAME as USERNAME5_, users0_.EMAIL as EMAIL5_, users0_1_.STATUS as STATUS6_, users0_1_.FK_PLANNER_PLANNERCOMPANY as FK4_6_, users0_1_.PHONE as PHONE6_, case when users0_1_.ID is not null then 1 when users0_.ID is not null then 0 end as clazz_ from USERS users0_ left outer join PLANNER users0_1_ on users0_.ID=users0_1_.ID where users0_.USERNAME=?



anyone has an idea why this could happen? any help or hint is really appreciated!

Thank you!


Top
 Profile  
 
 Post subject: inheritance error?
PostPosted: Fri Jan 25, 2008 11:35 am 
Newbie

Joined: Sat Jan 19, 2008 11:32 am
Posts: 2
Hi,

Have you tried running the sql directly against both databases? I'm assuming that you have different db's in the test and developer environments which may be a bad assumption.

Also, if you could post your hibernate mapping file that might help forum users to debug your issue.

gasser


Top
 Profile  
 
 Post subject: Re: inheritance error?
PostPosted: Fri Jan 25, 2008 12:10 pm 
Newbie

Joined: Wed Dec 05, 2007 7:03 am
Posts: 2
ferguman wrote:
Hi,

Have you tried running the sql directly against both databases? I'm assuming that you have different db's in the test and developer environments which may be a bad assumption.


i did, it gave the correct results. also we tried to connect to the test database from the developer environment, and still we could not reproduce the problem... :(

Quote:
Also, if you could post your hibernate mapping file that might help forum users to debug your issue.


we dont have mapping file, we used annotations.

the two classes in question:

Code:
import ...;


@Entity
@Table(name = "PLANNER", uniqueConstraints = {})
public class Planner extends Users implements Cloneable {

   // Fields

   private List<TechnicalChangePart> changeParts;
   
   private List<UploadedPackage> uploadedPackages;
   
   private Plannercompany plannercompany;

   private String phone;

   private List<Orders> orderses = new ArrayList<Orders>(0);

   private PlannerStatus status;   

   @OneToMany(cascade= {CascadeType.PERSIST}, fetch=FetchType.LAZY, mappedBy="planner")
   @Cascade (org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   public List<TechnicalChangePart> getChangeParts() {
      return changeParts;
   }

   public void setChangeParts(List<TechnicalChangePart> changeParts) {
      this.changeParts = changeParts;
   }

   @ManyToOne(cascade = {CascadeType.PERSIST}, fetch = FetchType.LAZY)
   @JoinColumn(name = "FK_PLANNER_PLANNERCOMPANY", unique = false, nullable = true, insertable = true, updatable = true)
   @Cascade (org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   private Plannercompany getPlannercompanyx() {
      return this.plannercompany;
   }

   private void setPlannercompanyx(Plannercompany plannercompany) {
      this.plannercompany = plannercompany;
   }
   
   @Transient   
   public Plannercompany getPlannercompany() {
      return getPlannercompanyx();
   }
   @Transient
   public void setPlannercompany(Plannercompany plannercompany) {
      
      if (this.plannercompany != null) {
         this.plannercompany.getPlanners().remove(this);
      }
      
      if (plannercompany != null) {
         plannercompany.getPlanners().add(this);
      }
      
      this.plannercompany = plannercompany;
   }

   @Column(name = "PHONE", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
   public String getPhone() {
      return this.phone;
   }

   public void setPhone(String phone) {
      this.phone = phone;
   }

   @Enumerated(EnumType.ORDINAL)
   @Column(name = "STATUS", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
   public PlannerStatus getStatus() {
      return this.status;
   }

   public void setStatus(PlannerStatus status) {
      this.status = status;
   }

   @OneToMany(cascade = { CascadeType.PERSIST }, fetch = FetchType.LAZY, mappedBy = "plannerx")
   @Cascade (org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   public List<Orders> getOrderses() {
      return this.orderses;
   }

   public void setOrderses(List<Orders> orderses) {
      this.orderses = orderses;
   }
   
   
   
   @OneToMany(cascade= {CascadeType.PERSIST}, fetch= FetchType.LAZY, mappedBy="planner")
   @Cascade (org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   public List<UploadedPackage> getUploadedPackages() {
      return uploadedPackages;
   }

   public void setUploadedPackages(List<UploadedPackage> parts) {
      this.uploadedPackages = parts;
   }

}


and

Code:
import ...;

@Entity
@Table(name = "USERS",  uniqueConstraints = {})
@Inheritance(strategy = InheritanceType.JOINED)
public class Users extends HibernateObject {

   // Fields

   private String username;

   private String email;

   private String name;

   private List<TechnicalChange> technicalChanges = new ArrayList<TechnicalChange>(
         0);

   private List<PostOfficeUser> postOfficeUsers = new ArrayList<PostOfficeUser>(0);

   @Column(name = "USERNAME", unique = true, nullable = false, insertable = true, updatable = true, length = 100)
   public String getUsername() {
      return this.username;
   }

   public void setUsername(String username) {
      this.username = username;
   }

   @Column(name = "EMAIL", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
   public String getEmail() {
      return this.email;
   }

   public void setEmail(String email) {
      this.email = email;
   }

   @Column(name = "NAME", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
   public String getName() {
      return this.name;
   }

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

   @OneToMany(cascade = { CascadeType.PERSIST }, fetch = FetchType.LAZY, mappedBy = "usersx")
   @Cascade (org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   public List<TechnicalChange> getTechnicalChanges() {
      return this.technicalChanges;
   }

   public void setTechnicalChanges(List<TechnicalChange> technicalChanges) {
      this.technicalChanges = technicalChanges;
   }

   @OneToMany(cascade = { CascadeType.PERSIST }, fetch = FetchType.LAZY, mappedBy = "usersx")
   @Cascade (org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   public List<PostOfficeUser> getPostOfficeUsers() {
      return this.postOfficeUsers;
   }

   public void setPostOfficeUsers(List<PostOfficeUser> postOfficeUsers) {
      this.postOfficeUsers = postOfficeUsers;
   }

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.