- This topic has 4 replies, 2 voices, and was last updated 18 years, 9 months ago by Stephen Eaton.
-
AuthorPosts
-
Stephen EatonMemberG’day Guys,
Having a problem generating a simple many-one relationships from the ‘create hibernate mapping wizard’ in the DB Explorer. Using HSQLDB version 1.8.0.2 as a standalone database in this project.
I’ve come across previous posts regarding similar problems and have tried the select all tables and generate, but still fails to create the relationship mappings within the mapping files.
pojos are all created and mapping files are created…just no many-one mappings in the relevant mapping files.
ER mapper shows correct relationships.
drop table SENSOR_DATA if exists; drop table SENSORS if exists; create table "SENSORS"( "SID" INTEGER(0) not null, "NAME" VARCHAR(16) not null, "DESCRIPTION" VARCHAR(0), "TYPE" VARCHAR(0) not null, "UNIT" VARCHAR(4)not null, "PORT" VARCHAR(5) not null, primary key (sid) ) create table "SENSOR_DATA"( "ID" INTEGER(0) not null, "SID" INTEGER(0) not null, "TIME" TIMESTAMP default 'now', "VALUE" DOUBLE not null, primary key(id), foreign key(sid) references SENSORS(sid) ) insert into SENSORS(sid,name,description,type,unit,port) values (1,'Temp1','Server room temperature','TEMP','DEGC','COM6');
*** Date: Wed Mar 15 22:15:19 WST 2006
*** System properties:
OS=WindowsXP
OS version=5.1
Java version=1.5.0_04*** MyEclipse details:
MyEclipse Enterprise WorkbenchVersion: 4.1.1 GA
Build id: 20060228-4.1.1-GA*** Eclipse details:
Eclipse SDKVersion: 3.1.0
Build id: I20050627-1435Eclipse Platform
Version: 3.1.0
Build id: I20050627-1435Eclipse RCP
Version: 3.1.0
Build id: I20050627-1435Eclipse Java Development Tools
Version: 3.1.0
Build id: I20050627-1435Eclipse Plug-in Development Environment
Version: 3.1.0
Build id: I20050627-1435Eclipse Project SDK
Version: 3.1.0
Build id: I20050627-1435Eclipse startup command=-os
win32
-ws
win32
-arch
x86
-launcher
C:\java\eclipse_3_1\eclipse.exe
-name
Eclipse
-showsplash
600
-exitdata
1398_44
-vm
C:\WINDOWS\SYSTEM32\javaw.exe
Haris PecoMembermadeinoz,
I have tried reproduce your case.I have to change your schema, because constructions INTEGER(0) or VARCHAR(0) are invalid
This is schema script (i run it from myeclipse sql editor on hsqldb 1.8.0)drop table SENSOR_DATA if exists; drop table SENSORS if exists; create table "SENSORS"( "SID" INTEGER not null, "NAME" VARCHAR(16) not null, "DESCRIPTION" VARCHAR(20), "TYPE" VARCHAR(20) not null, "UNIT" VARCHAR(4)not null, "PORT" VARCHAR(5) not null, primary key (sid) ) create table "SENSOR_DATA"( "ID" INTEGER not null, "SID" INTEGER not null, "TIME" TIMESTAMP default 'now', "VALUE" DOUBLE not null, primary key(id), foreign key(sid) references SENSORS(sid) ) insert into SENSORS(sid,name,description,type,unit,port) values (1,'Temp1','Server room temperature','TEMP','DEGC','COM6');
When i call hibernate mapping for this tables, I get next (many-to-one and one-to-many have created)
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="test.Sensors" table="SENSORS" schema="PUBLIC"> <id name="sid" type="integer"> <column name="SID" /> <generator class="assigned" /> </id> <property name="name" type="string"> <column name="NAME" length="16" not-null="true" /> </property> <property name="description" type="string"> <column name="DESCRIPTION" length="20" /> </property> <property name="type" type="string"> <column name="TYPE" length="20" not-null="true" /> </property> <property name="unit" type="string"> <column name="UNIT" length="4" not-null="true" /> </property> <property name="port" type="string"> <column name="PORT" length="5" not-null="true" /> </property> <set name="sensorDatas" inverse="true"> <key> <column name="SID" not-null="true" /> </key> <one-to-many class="test.SensorData" /> </set> </class> </hibernate-mapping> <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="test.SensorData" table="SENSOR_DATA" schema="PUBLIC"> <id name="id" type="integer"> <column name="ID" /> <generator class="assigned" /> </id> <many-to-one name="sensors" class="test.Sensors" fetch="select"> <column name="SID" not-null="true" /> </many-to-one> <property name="time" type="timestamp"> <column name="TIME" length="6" /> </property> <property name="value" type="double"> <column name="VALUE" precision="0" scale="0" not-null="true" /> </property> </class> </hibernate-mapping>
I make test for simple query (loading classes) and it work fine.
If you have mapping and POJO then you probably haven’t PK or FK
Check this in DB Explorer (click on table and see Table Info view)Best
Stephen EatonMemberThanks for the quick response…I’ll follow up on those and get back to you.
Stephen EatonMemberHmm…Tried and still failing….the VARCHAR(0) anf INTEGER(0) were as generated from the DB browser. Even if I copy and paste your script it still returns INTEGER(0) on the generated table script.
I must be missing something in the steps. When I generate the mappings I select the tables from DB Browser, click on generate Hibernate Mapping, then with the wizard I just hit next, next, next then Finish.
To rule out my installation I have re-installed from afresh, both Eclipse and Myeclipse. Config below. I noticed from my config that it’s using Java version=1.5.0_04. what Jversion should I be using for myeclipse? 1.4? Where do I set this for myeclipse? or is it getting it from the system environment?
*** Date: Thu Mar 16 12:29:01 WST 2006
*** System properties:
OS=WindowsXP
OS version=5.1
Java version=1.5.0_04*** MyEclipse details:
MyEclipse Enterprise WorkbenchVersion: 4.1.1 GA
Build id: 20060309-4.1.1-GA*** Eclipse details:
Eclipse SDKVersion: 3.1.2
Build id: M20060118-1600Eclipse Platform
Version: 3.1.2
Build id: M20060118-1600Eclipse RCP
Version: 3.1.2
Build id: M20060118-1600Eclipse Java Development Tools
Version: 3.1.2
Build id: M20060118-1600Eclipse Plug-in Development Environment
Version: 3.1.2
Build id: M20060118-1600Eclipse Project SDK
Version: 3.1.2
Build id: M20060118-1600Eclipse startup command=-os
win32
-ws
win32
-arch
x86
-launcher
C:\java\eclipse\eclipse.exe
-name
Eclipse
-showsplash
600
-exitdata
11f0_3c
-vm
C:\WINDOWS\SYSTEM32\javaw.exe
Stephen EatonMemberOk All fixed…..Found the problem was the actual HSQLDB Jar File I was using was infact 1.7.0.x not 1.8.0.x I had picked up the wrong one when I configured my driver. This also seems to have fixed the INTEGER(0) issue on the generated script.
Thanks again for you help 🙂
-
AuthorPosts