-->
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.  [ 7 posts ] 
Author Message
 Post subject: Invalid characters allowed in property name,but not for list
PostPosted: Tue Jan 31, 2006 6:16 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 7:28 am
Posts: 38
Hibernate version:3.1.1

Mapping documents:

<class>
....
<property name="invalid-name" column="validName">
<List name="invalid-name" node="validName">
<key>....</key>
<one-to-many class=".....class">
</list>
</class>




Name and version of the database you are using: MSSqlServer 7


As you can see, invalid characters are allowed for properties, as long as the column attribute, specifies a valid name without any invalid characters.

This however is not the case with List.

Is this a bug, or is there a different way of doing it?


Top
 Profile  
 
 Post subject: ?
PostPosted: Tue Jan 31, 2006 7:27 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Why do you need those 'invalid' names?

Invalid name does not make sense in both cases because name is the name of Java class property and Java method names do not allow dashes.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 4:38 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 7:28 am
Posts: 38
Thanks for you reply.

The reason why I need these invalid charactes is because we have an application that parses XML instance documents or XML schemas/dtd's and a number of formats and then deploy/create Java code that represents that model/structure.

Now obviously we don't create java variables with those invalid charactes as they are invalid. Instead we create a generic method, that would allow me to set the value of a variable, passing in the invalid name. There is a lot of structural things that depends on me using this method.

I also use an Accessor on the property, that will actually call the generic method in order to set the value of the variable.

I hope this explains it a bit more.

Thanks again for your help I appreciate it.


Top
 Profile  
 
 Post subject: access
PostPosted: Wed Feb 01, 2006 1:12 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Well, you still need valid 'name' values in the hibernate mapping, although column name and node can be invalid names in Java.
Note that you do not have to have setters and getter if you will specify access=”field” or provide your own org.hibernate.property.PropertyAccessor

http://www.hibernate.org/hib_docs/v3/re ... n-property

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 5:31 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 7:28 am
Posts: 38
I know I can access the field directly, but I don't want to. There is other parts of my code that rely on me using this method, so I have to use a PropertyAccesor.

I know that the name I want to use is invalid in Java, but then I shoudn't be allowed to set the name to an invalid name on a property. I is the inconsistancy between properties and lists, that bothers me.

Please have a look at my code below:

Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="biz.c24.io.xmltest.schema.example.v0.v0.v0" auto-import="false">
   <class lazy="false" name="biz.c24.io.xmltest.schema.example.v0.v0.v0.PurchaseorderLocalImpl">
      <id unsaved-value="null" name="idKey">
         <generator class="native"/>
      </id>
      <list access="biz.c24.io.api.presentation.CollectionAccessor" node="lineitem" lazy="false" name="line-item">
         <key>
            <column name="purchaseorder_lineitem_id"/>
         </key>
         <list-index column="_index"/>
         <one-to-many class="biz.c24.io.xmltest.schema.example.v0.v0.v0.LineitemImpl"/>
      </list>
      <property column="okok" type="java.lang.Boolean" access="biz.c24.io.api.presentation.PropertyAccessor" not-null="false" name="ok-ok"/>
   </class>
</hibernate-mapping>


Property okok works fine, but the list gives problems.

I have to use this "Invalid" alias, is there another way?

Thanks again


Top
 Profile  
 
 Post subject: tha cause
PostPosted: Thu Feb 02, 2006 12:39 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Well, there is a reason for the behavior: Hibernate uses column name in case of property to create SQL alias for column in the select. When dealing with collections H uses attribute “name” to create table alias in the SQL query, which causes invalid SQL because '-' is not permitted in SQL.

IMO You may file a feature request asking H to check if name is valid when it creates SQL.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 12:56 pm 
Beginner
Beginner

Joined: Mon Aug 02, 2004 7:28 am
Posts: 38
Thanks for you help, I appreciate it. I'll file a feature request.


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