-->
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: Simple underscore in the middle of a column name fails
PostPosted: Mon Feb 25, 2008 5:50 pm 
Newbie

Joined: Mon Feb 25, 2008 5:37 pm
Posts: 2
Hi folks,

I'm using the JPA and JBoss 4.2.0, and I'm having some trouble with a column name that has an underscore in the middle, named "shift_state"; the field is actually an enum, and has appropriate getters and setters. When I use the javax.persistence.Column annotation with name="shift_state", and use the literal "shift_state" in my queries, they fail silently with no results.

When I take out the @Column(name="shift_state") annotation, and change my HQL to use "shiftState = :boundParam", I get my expected results. Either way, no warning is thrown, and the generated SQL using "hibernate.show_sql" looks great.

Here's some of the specifics:
An example of a working query:
Code:
      Query alreadyWorkingQuery = entityManager.createQuery(
            "from EmployeeShiftVO WHERE "+
            (startDate != null ? "DATE(shift_date) >= DATE(:startDate) AND " : "DATE(shift_date) >= DATE(NOW()) AND ") +
            (endDate != null ? "DATE(shift_date) <= DATE(:endDate) AND " : "" )+
            "nextElement is null AND "+
            "employee = :employee AND "+
            "(shiftState = :shiftState1 OR shiftState = :shiftState2)"
            )
            .setParameter("employee", employee)
            .setParameter("shiftState1", EmployeeShiftState.ADDED_SEAT)
            .setParameter("shiftState2", EmployeeShiftState.ALLOCATED_SEAT)
            ;

      if(startDate != null)
         alreadyWorkingQuery.setParameter("startDate", startDate);
      
      if(endDate != null)
         alreadyWorkingQuery.setParameter("endDate", endDate);


An example of a working mapping in my POJO class:
Code:
   private EmployeeShiftState shift_state;

   @Column
   @Enumerated(value=EnumType.ORDINAL)
   public EmployeeShiftState getShiftState()
   {
      return shift_state;
   }

   public void setShiftState(EmployeeShiftState shiftState)
   {
      this.shift_state = shiftState;
   }


The generated/dumped AST:
Code:
2008-02-25 16:42:16,574 INFO  [STDOUT] Hibernate:
    select
        employeesh0_.id as id131_,
        employeesh0_.version as version131_,
        employeesh0_.nextElement_id as nextEle12_131_,
        employeesh0_.role as role131_,
        employeesh0_.employee_ID as employee13_131_,
        employeesh0_.spanish as spanish131_,
        employeesh0_.shift_date as shift5_131_,
        employeesh0_.survey_id as survey14_131_,
        employeesh0_.shiftConfigVO_id as shiftCo15_131_,
        employeesh0_.previousElement_id as previou11_131_,
        employeesh0_.shiftState as shiftState131_,
        employeesh0_.last_updated_timestamp as last7_131_,
        employeesh0_.last_updated_by as last8_131_,
        employeesh0_.created_by as created9_131_,
        employeesh0_.creation_timestamp as creation10_131_
    from
        employee_shifts employeesh0_
    where
        date(shift_date)>=date(now())
        and (
            employeesh0_.nextElement_id is null
        )
        and employeesh0_.employee_ID=?
        and (
            employeesh0_.shiftState=?
            or employeesh0_.shiftState=?
        )


Now, here's the broken stuff that returns zero results (nothing appears wrong to me):

Broken query (?):
Code:
      Query alreadyWorkingQuery = entityManager.createQuery(
            "from EmployeeShiftVO WHERE "+
            (startDate != null ? "DATE(shift_date) >= DATE(:startDate) AND " : "DATE(shift_date) >= DATE(NOW()) AND ") +
            (endDate != null ? "DATE(shift_date) <= DATE(:endDate) AND " : "" )+
            "nextElement is null AND "+
            "employee = :employee AND "+
            "(shift_state = :shiftState1 OR shift_state = :shiftState2)"
            )
            .setParameter("employee", employee)
            .setParameter("shiftState1", EmployeeShiftState.ADDED_SEAT)
            .setParameter("shiftState2", EmployeeShiftState.ALLOCATED_SEAT)
            ;

if(startDate != null)
         alreadyWorkingQuery.setParameter("startDate", startDate);
      
      if(endDate != null)
         alreadyWorkingQuery.setParameter("endDate", endDate);


The only difference in the mapping is:
Code:
@Column(name="shift_state")


The broken AST:
Code:
2008-02-25 16:46:28,055 INFO  [STDOUT] Hibernate:
    select
        employeesh0_.id as id186_,
        employeesh0_.version as version186_,
        employeesh0_.nextElement_id as nextEle12_186_,
        employeesh0_.role as role186_,
        employeesh0_.employee_ID as employee14_186_,
        employeesh0_.spanish as spanish186_,
        employeesh0_.shift_date as shift5_186_,
        employeesh0_.survey_id as survey13_186_,
        employeesh0_.shiftConfigVO_id as shiftCo15_186_,
        employeesh0_.previousElement_id as previou11_186_,
        employeesh0_.shift_state as shift6_186_,
        employeesh0_.last_updated_timestamp as last7_186_,
        employeesh0_.last_updated_by as last8_186_,
        employeesh0_.created_by as created9_186_,
        employeesh0_.creation_timestamp as creation10_186_
    from
        employee_shifts employeesh0_
    where
        date(shift_date)>=date(now())
        and (
            employeesh0_.nextElement_id is null
        )
        and employeesh0_.employee_ID=?
        and (
            shift_state=?
            or shift_state=?
        )


Does Hibernate hate underscores? Thank you for any responses!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 9:55 am 
Newbie

Joined: Mon Feb 25, 2008 5:37 pm
Posts: 2
Just an update... Hibernate's query language prefers the syntax from the getters and setters, NOT the @Column(name="blah") syntax.

HOWEVER, MySQL appears to throw NO error with the MySQL5InnoDB dialect. I had to switch to Hypersonic to find out there was even a problem. It would be great if Hibernate's AST generator could complain about this, even at the debug level.


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.