-->
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: Hibernate is not escaping words when using "`"
PostPosted: Mon Jun 08, 2009 11:34 am 
Newbie

Joined: Mon Jun 08, 2009 11:07 am
Posts: 1
Hello,

Maybe I'm misusing this great tool that is Hibernate but I most think it's a bug rather then misuse.
My situation is that I did a Many-to-Many map between a table called User and a table called Group and everyone know that these 2 words are reserved words in SQL. Even though I'm using the "`" surrounding these words and for most cases the Hibernate is using the adequate escape char (in my case for MS SQL Server it's using [ and ]) but it's producing a small sub-sql which is not doing this escape. These is the sql I'm talking about:

Code:
select
   groups0_.[UserID] as UserID2_1_,
   groups0_.[GroupID] as GroupID1_1_,
   (
      select
         a15."Name"
      from
         Group a15
      where
         a15.groups0_.[GroupID] = groups0_.[GroupID]
   ) as formula5_1_,
   group1_.[GroupID] as GroupID1_2_0_,
   group1_.[Description] as Descript2_2_0_,
   group1_.[Name] as Name3_2_0_
from
   [MapUserGroup] groups0_
   left outer join [Group] group1_ on groups0_.[GroupID] = group1_.[GroupID]
where groups0_.[UserID] = ?


Note that in the sub-sql it's not using the escape chars in the name of the table but in the remaining SQL it does use it. Another issue is that Hibernate is trying to access this a15.groups0_.[GroupID] field but the groups0_ portion does not belongs to a15 but it's outside of the sub-sql.

Any thoughts ?

This is my relevant code. Note that I'm using the "`" chars where it's necessary:

Code:
@Entity
@Table(name="`Group`")
public class Group implements Serializable {
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="`GroupID`")
   private int groupId;
   
   @Column(name="`Name`")
   private String name;

   @Column(name="`Description`")
   private String description;
      
   @ManyToMany
   @JoinTable(name="`MapUserGroup`",
            joinColumns=@JoinColumn(name="`GroupID`"),
            inverseJoinColumns=@JoinColumn(name="`UserID`"))
   @MapKey(name="userName")
   private Map<String, User> users;
...
}

...

@Entity
@Table(name="`User`")
public class User implements Serializable {
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="`UserID`")
   private int userId;
   
   @Column(name="`UserName`")
   private String userName;
   
   @Column(name="`Password`")
   private String password;
      
   @ManyToMany
   @JoinTable(name="`MapUserGroup`",
         joinColumns=@JoinColumn(name="`UserID`"),
         inverseJoinColumns=@JoinColumn(name="`GroupID`"))
   @MapKey(name="name")   
   private Map<String, Group> groups;
...
}


Thanks in advance

Lucas


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.