-->
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: Class type instead primitive type
PostPosted: Sun Feb 13, 2005 2:10 pm 
Beginner
Beginner

Joined: Fri Aug 20, 2004 3:45 pm
Posts: 22
Location: Florence - ITALY
I was regenerated bean from hbm using new version (2.1.3).
A plethora of compilation error was born.
The problem is who the new version create java type instead primitive
type by default.

Is this possible? How can i generate the old-type bean (with
primitive type when I use integer, long,....) ?

Thanks.

Gianni Antini (Gabby)
Florence, ITALY

Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate tool version: 2.1.3


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You have not provided enough details (how about a mapping document).

In anycase, the fields in question most likely don't have not-null="true" thus a primitive is not appropriate, eg, cannot be null.


Top
 Profile  
 
 Post subject: hbm2java generated wrapper class instead of primitive
PostPosted: Thu Feb 17, 2005 4:03 pm 
Newbie

Joined: Thu Feb 17, 2005 3:50 pm
Posts: 2
Location: western, ny usa
I had the same problem hibernate-extensions-2.1.3. I mapped a property (volume) to be short but it generated as the wrapper Short. When I entered "java.lang.short," the generated class was the primitive short. The documentation seems to indicate the opposite; that if I wanted Short, I would have to specify java.lang.Short. Am I missing something?


My mapping file is:

<?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>

<class name="com.oreilly.hh.Track" table="TRACK">
<meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliott (with help from Hibernate)
</meta>

<id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

<property name="title" type="string" no-null="true"/>

<property name="volume" type="short">
<meta attribute="field-description">How loud to play the track</meta>
</property>

</class>

</hibernate-mapping>



The generated class is:

package com.oreilly.hh;

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


/**
* Represents a single playable track in the music database.
* @author Jim Elliott (with help from Hibernate)
*
*/
public class Track implements Serializable {

/** identifier field */
private Integer id;

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

/** nullable persistent field */
private Short volume;

/** full constructor */
public Track(String title, Short volume) {
this.title = title;
this.volume = volume;
}

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

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

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

public String getTitle() {
return this.title;
}

public void setTitle(String title) {
this.title = title;
}

/**
* How loud to play the track
*/
public Short getVolume() {
return this.volume;
}

public void setVolume(Short volume) {
this.volume = volume;
}

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

}


Top
 Profile  
 
 Post subject: Okay, not i get it.
PostPosted: Thu Feb 17, 2005 5:29 pm 
Newbie

Joined: Thu Feb 17, 2005 3:50 pm
Posts: 2
Location: western, ny usa
I think I see now why you can't set the type to a primitive. I guess because I am used to defining the db first and then the java classes that match them, instead of the mapping (which could be used to build the db), I didn't get it. Now I see why you can't declare a primitive without having it be not-null! Sorry for the stupid question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 9:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
No problem with the question. Glad its sorted.
In anycase, this is good for others to reference when they do a search.


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.