-->
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: how to save a NULL value
PostPosted: Sun Mar 27, 2005 3:35 pm 
Newbie

Joined: Sun Mar 27, 2005 3:17 pm
Posts: 3
I will preface this by saying that I am fairly new to Hibernate and have tried my best to figure this out myself, for I feel this is a trivial issue. (I have searched the online documentation, the forums, and have purchased "Hibernate In Action")

I have a Sidelite that may or may not contain a GlassStyle. My problem arises when I attempt to remove a GlassStyle from a Sidelite. When I attempt this glassstyle_id is given the value 0, when I need for it to be NULL

Java Snippet
currentSidelite.setGlassStyle(null);

Hibernate version: 2.1.8

Mapping documents:
Code:
<hibernate-mapping package="com.crosscomm.plastpro.model">
    <class name="Sidelite" table="sidelite">
        <id name="id" column="id" type="long">
            <generator class="identity"/>
        </id>
        ...
        <many-to-one name="glassStyle" class="GlassStyle" column="glassstyle_id"/>
    </class>

    <class name="GlassStyle" table="glassstyle">
        <id name="id" column="id" type="long">
            <generator class="identity"/>
        </id>

        <property name="name" column="name" type="string" />
        <property name="partNumber" column="part_number" type="string" />
        <property name="notes" column="notes" type="string" />
        <property name="priority" column="priority" type="int"  not-null="true" />
        <set name="transoms" lazy="true" cascade="all">
            <key column="glassstyle_id" />
            <one-to-many class="com.crosscomm.plastpro.model.Transom" />
        </set>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 1:16 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Can you post the Java and DDL for the sidelite class and table? Thanks, Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 9:35 am 
Newbie

Joined: Sun Mar 27, 2005 3:17 pm
Posts: 3
DDL
CREATE TABLE `sidelite` (
`id` int(11) NOT NULL auto_increment,
`part_number` text,
`glassstyle_id` int(11) default NULL,
`category` int(11) default NULL,
`doorstyle_id` text,
`surfacetype` text,
`camingcolor_id` int(11) default NULL,
`dimension_ids` text,
`glass_dimension_id` int(11) default NULL,
`cutout_dimension_id` int(11) default NULL,
`is_daylight` int(1) default '0',
`notes` text,
PRIMARY KEY (`id`)
) TYPE=MyISAM

Java Code
Code:
package com.crosscomm.plastpro.model;

import java.util.Set;

public class Sidelite {
    private Long id;
    private String partNumber;
    private GlassStyle glassStyle;
    private Category category;
    private String style;
    private String surfaceType;
    private CamingColor caming;
    private Set dimensions;
    private Dimension glassDimension;
    private Dimension cutoutDimension;
    private boolean daylight;
    private String notes;
   
    public Sidelite() {
        glassStyle = new GlassStyle();
        category = new Category();
        caming = new CamingColor();
        glassDimension = new Dimension();
        cutoutDimension = new Dimension();
    }
   
    public CamingColor getCaming() {
        return caming;
    }

    public void setCaming(CamingColor caming) {
        this.caming = caming;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public Dimension getCutoutDimension() {
        return cutoutDimension;
    }

    public void setCutoutDimension(Dimension cutoutDimension) {
        this.cutoutDimension = cutoutDimension;
    }

    public boolean isDaylight() {
        return daylight;
    }

    public void setDaylight(boolean daylight) {
        this.daylight = daylight;
    }

    public Set getDimensions() {
        return dimensions;
    }

    public void setDimensions(Set dimensions) {
        this.dimensions = dimensions;
    }

    public Dimension getGlassDimension() {
        return glassDimension;
    }

    public void setGlassDimension(Dimension glassDimension) {
        this.glassDimension = glassDimension;
    }

    public GlassStyle getGlassStyle() {
        if (glassStyle == null) {
            glassStyle = new GlassStyle();
        }
        return glassStyle;
    }

    public void setGlassStyle(GlassStyle glassStyle) {
        this.glassStyle = glassStyle;
    }

    public Long getId() {
        return id;
    }

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

    public String getPartNumber() {
        return partNumber;
    }

    public void setPartNumber(String partNumber) {
        this.partNumber = partNumber;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public String getSurfaceType() {
        return surfaceType;
    }

    public void setSurfaceType(String surfaceType) {
        this.surfaceType = surfaceType;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:46 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
I think this is your problem, right here:

dsmith wrote:

public GlassStyle getGlassStyle() {
if (glassStyle == null) {
glassStyle = new GlassStyle();
}
return glassStyle;
}


Hibernate uses bean accessor methods to obtain the object values to persist to the database. So, it's doing what you're telling it to do!

HTH,
—ml—


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 29, 2005 11:39 am 
Newbie

Joined: Sun Mar 27, 2005 3:17 pm
Posts: 3
ml-

thanks for your help--i can't believe i missed that! it was added to make JSF happy when doing some EL:

Code:
#{sideliteHandler.currentSidelite.glassStyle.id}


-dsmith


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.