- This topic has 5 replies, 2 voices, and was last updated 18 years, 10 months ago by Seagate_UK.
-
AuthorPosts
-
Seagate_UKMemberHi,
I am using the database explorer to generate hibernate mappings for 85 tables in a SQL Server database. All but 26 are generated without any errors in the mapping files. All java classes are generated fine and compile.
The errors in the 26 dodgy ones are all the same:
The content of element type “class” must match “(meta*,subselect?,cache?,synchronize*,comment?,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,(query|sql-query)*)”. AppAffiliationlogo.hbm.xml evehibernate/src line 17 07 December 2005 15:34:20
I’ve seen this error on the forum but doesn’t help me. If I open one of the mapping files, comment out the “class” details, save it (now the error disappears), take out comments so it is back to generated version, save it(error returns as expected). However, if I take a copy of this file and paste it into the same directory with a new name, the original file does not display an error anymore, even though nothing in that file has changed! Weird. What could be causing this? Now and again different sets of files show errors.
Here is an example
=============table App_CapabilityPermission_Link – no primary key, foreign keys, constraints
create table “Opt2VoteServer”.”dbo”.”App_CapabilityPermission_Link”(
“Capp_SysCapability” int(10) not null,
“Capp_SysPermission” int(10) not null)mapping file
<?xml version=”1.0″ encoding=’UTF-8′?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd” ><!– Generated by MyEclipse Hibernate Tools –>
<!– Created Wed Dec 07 16:46:50 GMT 2005 –><hibernate-mapping package=”com.opt2vote.hibernate”>
<class name=”AppCapabilitypermissionLink” table=”App_CapabilityPermission_Link”>
<property name=”cappSyscapability” column=”Capp_SysCapability” type=”integer” not-null=”true” />
<property name=”cappSyspermission” column=”Capp_SysPermission” type=”integer” not-null=”true” />
</class></hibernate-mapping>
My setup details:
===========*** Date: Wed Dec 07 16:51:46 GMT 2005
*** System properties:
OS=WindowsXP
OS version=5.1
Java version=1.5.0_06*** MyEclipse details:
MyEclipse Enterprise WorkbenchVersion: 4.0.100 M1
Build id: 20051103-4.1-Milestone1*** Eclipse details:
Eclipse SDKVersion: 3.1.0
Build id: I20050627-1435Eclipse Platform
Version: 3.1.0
Build id: I20050627-1435Eclipse Java Development Tools
Version: 3.1.0
Build id: I20050627-1435Eclipse Project SDK
Version: 3.1.0
Build id: I20050627-1435Eclipse RCP
Version: 3.1.0
Build id: I20050627-1435Eclipse Plug-in Development Environment
Version: 3.1.0
Build id: I20050627-1435Eclipse startup command=-os
win32
-ws
win32
-arch
x86
-launcher
C:\Program Files\eclipse\3.1\eclipse\eclipse.exe
-name
Eclipse
-showsplash
600
-exitdata
93c_70
-vm
C:\WINDOWS\system32\javaw.exeTHANKS!
Riyad KallaMemberThe problem is that the tables do not have a PK defined, so the mapping generator is generating hibernate mapping files with an <id> clause, which is required per the DTD. Hibernate can only persist tables that have a PK, some way to uniquly identify the records.
Seagate_UKMemberThanks. I have added a primary key to this table so that it is a composite key and the mapping generation works.
OK this brings me to another question. We have many link tables defined to remove the many to many relationships. We weren’t planning to have primary keys on these tables. I assume this is not good practice, what do you think? We can create primary keys on all link tables so that they are composite keys and then generate the mapping from the schema. Is this the best use of hibernate. We want to do as little mapping by hand as possible (if any at all).
cheers
Martin
Riyad KallaMemberMartin,
I never think it’s a bad idea for a table to define a PK, even if you don’t necessarily need it. I’d suggest you go ahead and do it that way, save yourself the trouble, let the IDE generate the mappings and you guys work on the app. If later down the road you decide to go in and rewrite the generated mappings that’s always an option.
Seagate_UKMemberThat’s good to know. We have been prototyping an app using hibernate. We use some named queries to illustrate their features and place them inside the mapping files. However if we regenerate these mapping files the named queries will be lost. Is there any alternative place to store these separate from the mappings? Is there anyway to run these named queries via myeclipse? Also, is the 4.1M2 release on course for dec 12th – I see there will be a visual mapper in place there. That would be really useful.
cheers
Martin
Seagate_UKMemberAlso, can the version I have remove the naming convention prefixes from table names and field names?
cheers
Martin -
AuthorPosts