MyEclipse: Error in hibernate mapping files [Closed]

pdemilly - Oct 19, 2004 - 12:12 AM
Post subject: Error in hibernate mapping files [Closed]
Hi,

I am trying to follow the tutorial to create a J2EE application. I started with hybernate since I want to interface quickly to our existing database. I generated the file mapping using your tool, but it has an error:

The content of element type "class" must match
"(meta*,(cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,(subclass*|joined-subclass*))".

What do I need to do to fix that error?

TIA

Pascal
support-rkalla - Oct 19, 2004 - 12:27 AM
Post subject:
Pascal,
This is the hbm.xml file that is giving the error right? Can you paste it here for us to see?
pdemilly - Oct 19, 2004 - 01:08 AM
Post subject:
Here is my hbm.xml. Apart from the error you will also notice that the property name doesn't keep the proper capitalization.

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" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration.                   -->
<!-- Created Mon Oct 18 16:01:56 PDT 2004                         -->
<hibernate-mapping package="com.newgenesys.crs.backend.hibernate">
   <class name="Items" table="Items">
      <property name="sku" column="SKU" type="java.lang.String"
         not-null="true" />
      <property name="description" column="Description"
         type="java.lang.String" not-null="true" />
      <property name="model" column="Model" type="java.lang.String"
         not-null="true" />
      <property name="productcode" column="ProductCode"
         type="java.lang.String" not-null="true" />
      <property name="price1" column="Price1" type="java.lang.Float"
         not-null="true" />
      <property name="price2" column="Price2" type="java.lang.Float"
         not-null="true" />
      <property name="price3" column="Price3" type="java.lang.Float"
         not-null="true" />
      <property name="currentpriceindex" column="CurrentPriceIndex"
         type="java.lang.Short" not-null="true" />
      <property name="averagecost" column="AverageCost"
         type="java.lang.Double" not-null="true" />
      <property name="lastcost" column="LastCost" type="java.lang.Double"
         not-null="true" />
      <property name="lastcostdate" column="LastCostDate"
         type="java.lang.Integer" />
      <property name="qtyonhand" column="QtyOnHand" type="java.lang.Integer"
         not-null="true" />
      <property name="reorderlevel" column="ReorderLevel"
         type="java.lang.Integer" not-null="true" />
      <property name="qtycommitted" column="QtyCommitted"
         type="java.lang.Integer" not-null="true" />
      <property name="qtyonorder" column="QtyOnOrder"
         type="java.lang.Integer" not-null="true" />
      <property name="lastorderdate" column="LastOrderDate"
         type="java.lang.Integer" />
      <property name="lastpurchaseorder" column="LastPurchaseOrder"
         type="java.lang.String" not-null="true" />
      <property name="primaryvendor" column="PrimaryVendor"
         type="java.lang.String" not-null="true" />
      <property name="backordercode" column="BackOrderCode"
         type="java.lang.String" not-null="true" />
      <property name="taxablecode" column="TaxableCode"
         type="java.lang.String" not-null="true" />
      <property name="locationcode" column="LocationCode"
         type="java.lang.String" not-null="true" />
      <property name="stockstatus" column="StockStatus"
         type="java.lang.String" not-null="true" />
      <property name="lastsolddate" column="LastSoldDate"
         type="java.lang.Integer" />
      <property name="qtysoldperiodtodate" column="QtySoldPeriodToDate"
         type="java.lang.Integer" not-null="true" />
      <property name="qtysoldyeartodate" column="QtySoldYearToDate"
         type="java.lang.Integer" not-null="true" />
      <property name="salesperiodtodate" column="SalesPeriodToDate"
         type="java.lang.Double" not-null="true" />
      <property name="salesyeartodate" column="SalesYearToDate"
         type="java.lang.Double" not-null="true" />
      <property name="costperiodtodate" column="CostPeriodToDate"
         type="java.lang.Double" not-null="true" />
      <property name="costyeartodate" column="CostYearToDate"
         type="java.lang.Double" not-null="true" />
   </class>
</hibernate-mapping>



Thanks for helping me with this

Pascal
support-rkalla - Oct 19, 2004 - 02:23 AM
Post subject:
Pascal,
Does this table not have any PKs or FKs in it? It looks like the hibernate tool mapped everything to a property and forgot to set a valid ID.
pdemilly - Oct 19, 2004 - 04:19 AM
Post subject:
Yes it does. The SKU is PK. However the JDBC driver has its problems and sometimes fail to rerieve metadata. Maybe this is why.
support-rkalla - Oct 19, 2004 - 04:54 AM
Post subject:
Hmm could be, I've ask our hib dev to look at this. Stay tuned. In the mean time, is there another driver you can try with this DB?
support-jeff - Oct 19, 2004 - 05:02 AM
Post subject:
If the JDBC driver cannot access the proper metadata on PKs in the database, then you are out-of-luck I am afraid. You will need to manually alter the mapping file to make sku the id. Just be aware that if you chose to re-map the table at a later date, it will over-write your customizations so be sure to backup.

I suppose that a warning should be posted to the error logs - to bring this more clearly into focus as the problem.

As for capitalization, for now the mappings only handle the 'pseudo-SQL standard' of using underscores: attribute_with_this_name would become attributeWithThisName in java. attributeWithThisName in a database table would become attributewiththisname as you see in your mapping. This will be made more customizable in the future.
tamaki - Nov 09, 2004 - 05:19 AM
Post subject:
My problem seems smilar: the hibernate tool does not generate an <id> tag in the
mapping file. I followed the BasicDB demo and selected "native" generator in
the tool window. I am using MySQL. I am not familiar with database tools and
don't understand what PKs or SKU mean. Do I need to do something to the
database table in order to let the hibernate tool generate the <id> tag?

Thanks.

Hisao
support-jeff - Nov 09, 2004 - 11:20 PM
Post subject:
You must declare at least one column in a table to be a primary key in order for an id to be generated. Use the Db Explorer to view the table structure - is there a column that is marked as a primary key in the db browser? In the table view, is there an entry in the Primary Key tab? If not, that explains why there is no id generated.
tamaki - Nov 10, 2004 - 04:53 AM
Post subject:
Thanks jeff! I added a primary key to my table and now the id tag is generated.

Hisao
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits