-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate type generation default different in 2.1.2vs2.1.3?
PostPosted: Tue Nov 23, 2004 2:55 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Hibernate version: 2.1.7

After I upgraded extensions from 2.1.2 to 2.1.3 and I runned the Codegenerator tool it generates by default non-primitive types for my hibernate types (int becomes Integer and long becomes Long). This is different from 2.1.2, it is not mentioned (?) in the changelog.
Is this customizable ?

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 5:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - there shouldn't be changes it that area AFAIK.

Can you show the mapping.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 5:24 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping default-cascade="none">
   
   <class name="nl.dennie.vikie.model.Range" table="ranges">
      <meta attribute="class-code">
      <![CDATA[
   public synchronized long reserve(int block){
      if(getAmountAvailable().intValue()<block){
         return -1;
      }
      else{
         setAmountAvailable(new Integer(getAmountAvailable().intValue() - block));
         return getTill().longValue()-getAmountAvailable().intValue();
      }
   }
      ]]>         
      </meta>

      <id name="id" type="int" column="ID">
         <generator class="identity"/>
      </id>

      <property name="name" column="NAME" type="string"/>
      <property name="from" column="FROMVAL" type="long"/>
      <property name="amountAvailable" column="AVAILABLE" type="int"/>
      <property name="till" column="TILLVAL" type="long"/>

      <property name="timeOfCreation" column="TIME_OF_CREATION" type="calendar"/>

      <many-to-one name="customer" class="nl.dennie.vikie.model.Customer" column="CUSTOMERID" />
      <many-to-one name="parent" class="nl.dennie.vikie.model.Range" column="PARENTID" />

   </class>
</hibernate-mapping>


Generates

Code:
package nl.dennie.vikie.model;

import java.io.Serializable;
import java.util.Calendar;
import org.apache.commons.lang.builder.ToStringBuilder;


/** @author Hibernate CodeGenerator */
public class Range implements Serializable {

    /** identifier field */
    private Integer id;

    /** nullable persistent field */
    private String name;

    /** nullable persistent field */
    private Long from;

    /** nullable persistent field */
    private Integer amountAvailable;

    /** nullable persistent field */
    private Long till;

    /** nullable persistent field */
    private Calendar timeOfCreation;

    /** nullable persistent field */
    private nl.dennie.vikie.model.Customer customer;

    /** nullable persistent field */
    private nl.dennie.vikie.model.Range parent;

    /** full constructor */
    public Range(String name, Long from, Integer amountAvailable, Long till, Calendar timeOfCreation, nl.dennie.vikie.model.Customer customer, nl.dennie.vikie.model.Range parent) {
        this.name = name;
        this.from = from;
        this.amountAvailable = amountAvailable;
        this.till = till;
        this.timeOfCreation = timeOfCreation;
        this.customer = customer;
        this.parent = parent;
    }

    /** default constructor */
    public Range() {
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

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

    public Long getFrom() {
        return this.from;
    }

    public void setFrom(Long from) {
        this.from = from;
    }

    public Integer getAmountAvailable() {
        return this.amountAvailable;
    }

    public void setAmountAvailable(Integer amountAvailable) {
        this.amountAvailable = amountAvailable;
    }

    public Long getTill() {
        return this.till;
    }

    public void setTill(Long till) {
        this.till = till;
    }

    public Calendar getTimeOfCreation() {
        return this.timeOfCreation;
    }

    public void setTimeOfCreation(Calendar timeOfCreation) {
        this.timeOfCreation = timeOfCreation;
    }

    public nl.dennie.vikie.model.Customer getCustomer() {
        return this.customer;
    }

    public void setCustomer(nl.dennie.vikie.model.Customer customer) {
        this.customer = customer;
    }

    public nl.dennie.vikie.model.Range getParent() {
        return this.parent;
    }

    public void setParent(nl.dennie.vikie.model.Range parent) {
        this.parent = parent;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("id", getId())
            .toString();
    }

// The following is extra code specified in the hbm.xml files

      
   public synchronized long reserve(int block){
      if(getAmountAvailable().intValue()<block){
         return -1;
      }
      else{
         setAmountAvailable(new Integer(getAmountAvailable().intValue() - block));
         return getTill().longValue()-getAmountAvailable().intValue();
      }
   }
               
      
// end of extra code specified in the hbm.xml files
}


I am using the Hibernate tools plugin with IDEA.

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 6:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - looked into it now.

There was a change for this http://opensource.atlassian.com/project ... wse/HB-948

Which actually generates more correct code as your mapping actually states that the values can be null as "not-null" is default to false - meaning the values are nullable......

Sorry for missing out on that in the changelog.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 6:08 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Great, that was the issue indeed. I changed my mapping files and it works great now.

Thanks for helping. Max++

_________________
Dencel
- The sun has never seen a shadow -


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