-->
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.  [ 14 posts ] 
Author Message
 Post subject: metadata question (length, nullable)
PostPosted: Sat Dec 10, 2005 7:36 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I have try get length (not null,etc) metadata from mappings
i check classMapping and metadataProperty and I can't find length or not-null attribute in mappings (not-null is always true, but i don't know find length)

Can i find this attribute from configuration ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 8:48 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
You may be looking for org.hibernate.mapping.Column.getLength() ? It should be a few gets off of org.hibernate.mapping.Property somwhere.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 8:12 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I find Property from configuration classMapping, but length and nullable isn't good (it isn't from xml mappings) - nullable is always true, but length is fine for SimpleValue (simple column), but it isn't good for component mapping (for example many-to-one) - then i get default value (255)

i can find nullable in metadata too and this is always true - this is bug in last hibernate maybe
i work with last cvs
It is easier with annotation, but I don't use annotation, yet


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 8:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the column length is on the column and it does indeed come from the mapping files (as long as it is in there).

Show the mapping file that doesn't give you a column length as you expect.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 10:52 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
example :
class FinNks
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="yu.co.snpe.dbtable.model.hibernate"
   default-lazy="false">

   <class name="FinNks" table="FIN_NKS">

      <composite-id>
         <key-many-to-one name="finNk" column="NK" />
         <key-property name="red" column="RED"
            type="java.lang.Long" length="6" />
      </composite-id>

      <property name="datd" type="java.sql.Date" column="DATD"
         length="10" not-null="false"/>
      <property name="datv" type="java.sql.Date" column="DATV"
         length="10" />
      <property name="dug" type="java.math.BigDecimal" column="DUG"
         length="22" />
      <property name="pot" type="java.math.BigDecimal" column="POT"
         length="22" />
      <property name="sifd" type="java.lang.String" column="SIFD"
         length="40" />
      <property name="kifkuf" type="java.lang.String" column="KIFKUF"
         length="20" />
      <property name="anal" type="java.lang.String" column="ANAL"
         length="6" />
      <property name="dugs" type="java.lang.String" column="DUGS"
         length="1" />
      <property name="pots" type="java.lang.String" column="POTS"
         length="1" />
      <property name="potv" type="java.math.BigDecimal"
         formula="decode(pots,'S',-pot,pot)" />
      <property name="dugv" type="java.math.BigDecimal"
         formula="decode(dugs,'S',-dug,dug)" />
      <property name="sal" type="java.math.BigDecimal"
         formula="decode(dugs,'S',-nvl(dug,0),nvl(dug,0))-decode(pots,'S',-nvl(pot,0),nvl(pot,0))" />
      
      <many-to-one name="finKonto" class="FinKonto" not-null="false">
         <column name="KON" />
      </many-to-one>
      <many-to-one name="finOpn" class="FinOpn" not-null="false">
         <column name="OPN" />
      </many-to-one>
      <many-to-one name="finVal" class="FinVal" not-null="true">
         <column name="VAL" />
      </many-to-one>
   </class>
</hibernate-mapping>


length is fine, i can find length , but nullable isn't good
i try like this :

Code:
PersistentClass classMapping = getConfiguration().getClassMapping(FinNks.class.getName());
      Property property = classMapping.getProperty("datd");
      boolean nullable = property.getValue().isNullable();


or
Code:
PersistentClass classMapping = getConfiguration().getClassMapping(FinNks.class.getName());
      Property property = classMapping.getProperty("datd");
      Column column = (Column) property.getColumnIterator().next();
      boolean nullable = column.isNullable();


I get true always, for property datd (or datv - datv is nullable, but datd isn;t) and
for finKonto, finVal or finOpn - it's true always


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 11:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
for both property value and column it is still nullable ? ...sounds like a bug then (and we must be missing unit tests for this in the tools since they kinda rely on this one too)

Put the case in jira and i'll look into it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 1:25 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
http://opensource2.atlassian.com/projec ... e/HHH-1257

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 4:04 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
gavin reject JIRA, but i find reason for bug

i play with org.hibernate.test.bidi.AuctionTest2

this is test :
Code:
public void testNullable() {

      boolean nullable = isNullable(Auction.class.getName(),"successfulBid");

      assertTrue(!nullable);

      nullable = isNullable(Auction.class.getName(),"description");

      assertTrue(!nullable);

   }



   private boolean isNullable(String className,String propertyName) {

      PersistentClass classMapping = getCfg().getClassMapping(

            className);

      Property property = classMapping.getProperty(propertyName);

      Column column = (Column) property.getColumnIterator().next();

      return column.isNullable();

   }


when i set this mapping then it work fine (i can set not-null to true/false and it work fine)

Code:
...
<property name="description"/>
<many-to-one name="successfulBid" not-null="false"/>
...


now I set next mappings :



Code:
<property name="description" not-null="true">
         <column name="description"/>
      </property>
      <property name="end" column="endDatetime"/>
      <bag name="bids" inverse="true"
            cascade="persist">
         <key column="auctionId"/>
         <one-to-many class="Bid"/>
      </bag>
      <many-to-one name="successfulBid" not-null="true">
         <column name="successfulBid"></column>
      </many-to-one>


add column element

now i get nullable=true (for not-null="true" or not-null="false")


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 5:28 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
i play yet with this
when i have column element, then hibernate work with not-null in column element, no in property

for example, this :
Code:
    <property name="description">
         <column name="description"  not-null="true"/>
      </property>
      <many-to-one name="successfulBid">
         <column name="successfulBid"  not-null="true"/>
      </many-to-one>


work fine, but this :


Code:
<property name="description" not-null="true">
         <column name="description"  />
      </property>
      <many-to-one name="successfulBid" not-null="true">
         <column name="successfulBid"  />
      </many-to-one>


is it fine or bug ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 6:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it was rejected because there were no information at all in the bug (besides an asumption which were false).

Specifying an explicit column name and not-null on property definitly is ok in my mind as if you specificied a column attribute on property the not-null would apply to that column and not the nested one.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 7:44 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
i don't understand

Code:
<property name="description" not-null="true">
     <column name="description"  />
</property>


hibernate doesn't recognize not-null in this construction.
Is it ok ?

I can resolve my problem now, but it interest me


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 2:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
because you can also do:

Code:
<property name="description" column="firstCol" not-null="true">
     <column name="description"  />
</property>


and here you have two columns where the first one is not-null.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 8:28 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
It mean that is correct behavior ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 9:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i would say so yes...but I think what would make sense is that if all columns are not-null then the property should also be not-null; maybe

_________________
Max
Don't forget to rate


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