-->
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.  [ 2 posts ] 
Author Message
 Post subject: Failed to create table in one-to-one mapping
PostPosted: Tue Dec 02, 2003 10:22 am 
Regular
Regular

Joined: Tue Nov 04, 2003 12:37 pm
Posts: 57
Hello,

I am a beginner in Hibernate. But it seems can't generate the suitable schema when I use one-to-one mapping.

The following is my code and mapping.

Code:
package model;

import java.util.Date;
import util.DateTimeUtil;

/**
* Schedule class
*
*
* @hibernate.class
*    table="schedule"
*
* @struts.form
*    extends="org.apache.struts.validator.ValidatorForm"
*    include-all="true"
*/
public class Schedule {
   protected int scheduleId;
   protected Date startTime;
   protected double hours;
   protected Venue venue;


   public void setScheduleId(int scheduleId) {
      this.scheduleId = scheduleId;
   }

   /**
    * @hibernate.id
    *    generator-class="native"
    */   
   public int getScheduleId() {
      return scheduleId;
   }


   public void setStartTime(Date startTime) {
      this.startTime = startTime;
   }

   /**
    * @hibernate.property
    *    not-null="true"
    */
   public Date getStartTime() {
      return startTime;
   }
   
   
   public Date getEndTime() {
      return DateTimeUtil.addMinute(startTime, (int)(hours*60));
   }

   public void setHours(double hours) {
      this.hours = hours;
   }
   
   
   /**
    * @hibernate.property
    *    not-null="true"
    */
   public double getHours() {
      return hours;
   }
   

   public void setVenue(Venue venue) {
      this.venue = venue;
   }

   /**
    * @hibernate.one-to-one
    *    cascade="all"
    */
   public Venue getVenue() {
      return venue;
   }


Code:
package model;

/**
* Venue class
*
*
* @hibernate.class
*    table="venue"
*
* @struts.form
*    extends="org.apache.struts.validator.ValidatorForm"
*    include-all="true"
*/
public class Venue extends BaseObject {
   protected String shortName;
   protected String venueName;
   protected int venueId;

   public void setShortName(String shortName) {
      this.shortName = shortName;
   }

   /**
    * @hibernate.property
    *    column="shortName"
    *    not-null="false"
    */
   public String getShortName() {
      return shortName;
   }

   public void setVenueId(int venueId) {
      this.venueId = venueId;
   }

   /**
    * @hibernate.id
    *    column="venueId"
    *    generator-class="native"
    */
   public int getVenueId() {
      return venueId;
   }

   public void setVenueName(String venueName) {
      this.venueName = venueName;
   }

   /**
    * @hibernate.property
    *    column="venueName"
    *    not-null="true"
    */
   public String getVenueName() {
      return venueName;
   }
   
}



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>
    <class
        name="model.Schedule"
        table="schedule"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="scheduleId"
            column="scheduleId"
            type="int"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="startTime"
            type="java.util.Date"
            update="true"
            insert="true"
            column="startTime"
            not-null="true"
        />

        <property
            name="hours"
            type="double"
            update="true"
            insert="true"
            column="hours"
            not-null="true"
        />

        <one-to-one
            name="venue"
            class="model.Venue"
            cascade="all"
            outer-join="auto"
            constrained="false"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Schedule.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>




The following is generated by calling the SchemaExportTask in Ant.
Code:
CREATE TABLE VENUE(VENUEID INTEGER NOT NULL IDENTITY PRIMARY KEY,SHORTNAME VARCHAR(255),VENUENAME VARCHAR(255) NOT NULL)
CREATE TABLE SCHEDULE(SCHEDULEID INTEGER NOT NULL IDENTITY PRIMARY KEY,STARTTIME TIMESTAMP NOT NULL,HOURS DOUBLE NOT NULL)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 11:00 am 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
Read section "5.1.11. one-to-one" in Hibernate_Reference" 2.1.

mota


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