<generator class="increment" />
<id name="id" />
<property name="movie" />
<property name="showtimes" />
<property name="seatno" />
</class>
Exception
ERROR: HHH000196: Error parsing XML (2) : The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304)
at org.hibernate.cfg.Configuration.add(Configuration.java:516)
at org.hibernate.cfg.Configuration.add(Configuration.java:512)
at org.hibernate.cfg.Configuration.add(Configuration.java:686)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at test.ClientUsingAssigned.main(ClientUsingAssigned.java:16)
Use <generator> tag inside <Id>
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="id" type="int" column="id">
<generator class="increment"/>
</id>
<property name="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
<property name="salary" column="salary" type="int"/>
</class>
</hibernate-mapping>
Related
I have three persistent classes named:shops.class,user.class,vehicle.class and three hibernate mapping file shops.hbm.xml,users.hbm.xml,vehicle.hbm.xml
But i am getting following error in my users and vehicle mappingg file:
The content of element type "class" must match
"(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
shops.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 7, 2017 2:04:29 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="persistent_classes.shops" table="SHOPS">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<version name="version_id" type="int" unsaved-value="undefined">
<column name="VERSION_ID" />
</version>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="city" type="java.lang.String">
<column name="CITY" />
</property>
<property name="dealername" type="java.lang.String">
<column name="DEALERNAME" />
</property>
<property name="dealerno" type="java.lang.String">
<column name="DEALERNO" />
</property>
<property name="dealeremail" type="java.lang.String">
<column name="DEALEREMAIL" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="shops_string" type="java.lang.String">
<column name="SHOPS_STRING" />
</property>
<property name="login" type="boolean">
<column name="LOGIN" />
</property>
<list name="vehicles" inverse="false" table="VEHICLE" lazy="true">
<key>
<column name="store_id" />
</key>
<list-index></list-index>
<one-to-many class="persistent_classes.vehicle" />
</list>
<map name="users" table="SHOPS_MAP" lazy="true">
<key>
<column name="ID" />
</key>
<map-key type="java.lang.Integer"></map-key>
<element type="java.lang.Integer">
<column name="USERS" />
</element>
</map>
</class>
</hibernate-mapping>
vehicle.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 7, 2017 2:04:29 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="persistent_classes.vehicle" table="VEHICLE">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<property name="stock" type="int">
<column name="STOCK" />
</property>
<version name="version_id" type="int" unsaved-value="undefined">
<column name="VERSION_ID" />
</version>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="company" type="java.lang.String">
<column name="COMPANY" />
</property>
<property name="milage" type="java.lang.String">
<column name="MILAGE" />
</property>
<property name="year" type="java.lang.String">
<column name="YEAR" />
</property>
<property name="priceoriginal" type="java.lang.String">
<column name="PRICEORIGINAL" />
</property>
<property name="priceoffer" type="java.lang.String">
<column name="PRICEOFFER" />
</property>
<property name="vehicle_string" type="java.lang.String">
<column name="VEHICLE_STRING" />
</property>
</class>
</hibernate-mapping>
users.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 7, 2017 2:04:40 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="persistent_classes.users" table="USERS">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<map name="points" table="user_points" cascade="all">
<key column="user_id" />
<index column="shop_id" type="integer"></index>
<element column="points" type="string"></element>
</map>
<version name="version_id" type="int" unsaved-value="undefined">
<column name="VERSION_ID" />
</version>
<property name="login" type="boolean">
<column name="LOGIN" />
</property>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<property name="mobno" type="java.lang.String">
<column name="MOBNO" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="users_string" type="java.lang.String">
<column name="USERS_STRING" />
</property>
</class>
</hibernate-mapping>
I know this question is asked many times but all of that were related to not using tag. But i had used this tag in all files but still getting this error in users and vehicle file.
Please Help i am badly stuck with this.
Thanks in advance
version must be defined before property and map
Move it to be right after id definition in the users and vehicle hbm
I am trying to upgrade the Hibernate version of our project from 4.3 to 5.2.I have gone through the steps required for upgrading by going through the following documents
https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc
and the upgrade documents for other releases as well.
However after making the required changes, i am facing some runtime errors.
I took a very simple example model, where in my EntityModel looks like this:
EntityMetamodel(cemployees_create:[Attribute(name=LastName, type=string [non-identifier]),Attribute(name=FirstName, type=string [non-identifier]),Attribute(name=BirthDate, type=timestamp [non-identifier]),Attribute(name=HireDate, type=timestamp [non-identifier]),Attribute(name=Photo, type=binary [non-identifier]),Attribute(name=ReportsTo, type=cemployees_create [non-identifier,association]),Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])
However in version 5.2 when its trying to buildAttribute in AttributeFactory.java, its throwing the following exception:
java.lang.IllegalArgumentException: Expecting collection type [org.hibernate.type.BagType]
at org.hibernate.metamodel.internal.AttributeFactory.determineCollectionType(AttributeFactory.java:937)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:786)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:767)
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:548)
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:77)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:213)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:220)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
This is happening when its trying to build the Attribute for
Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])
Just wanted to check if someone has faced this problem before or if there are any resolutions to it. The same thing works perfectly fine with Hibernate 4.3
Adding the hibernate Entity Mapping file as well:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cfsuite.orm.manual.relationship.self_join">
<class entity-name="cemployees" table="Employees">
<tuplizer class="coldfusion.orm.hibernate.CFCTuplizer" entity-mode="dynamic-map"/>
<id column="EmployeeID" name="EmployeeID" type="integer">
<generator class="native"/>
</id>
<property column="LastName" name="LastName" type="string"/>
<property column="FirstName" name="FirstName" type="string"/>
<property column="Title" name="Title" type="string"/>
<property column="TitleOfCourtesy" name="TitleOfCourtesy" type="string"/>
<property column="BirthDate" name="BirthDate" type="date"/>
<property column="HireDate" name="HireDate" type="date"/>
<property column="Address" name="Address" type="string"/>
<property column="City" name="City" type="string"/>
<property column="Region" name="Region" type="string"/>
<property column="PostalCode" name="PostalCode" type="string"/>
<property column="Country" name="Country" type="string"/>
<property column="HomePhone" name="HomePhone" type="string"/>
<property column="Extension" name="Extension" type="string"/>
<property column="Photo" name="Photo" type="binary"/>
<property column="Notes" name="Notes" type="string"/>
<many-to-one column="ReportsTo" entity-name="cemployees" name="ReportsToObj"/>
<property column="PhotoPath" name="PhotoPath" type="string"/>
<bag cascade="all-delete-orphan" name="ReporteesArr">
<key column="ReportsTo"/>
<one-to-many entity-name="cemployees"/>
</bag>
</class>
</hibernate-mapping>
I have 3 tables represented by the following diagram:
I am trying to build a REST API that when /template is accessed by GET method,
the returned JSON will contain a templateDefinition object, that also contains a template type object. To that end I have created the following mapping files:
Template.hbm.xml
<hibernate-mapping package="com.reporttemplateengine.models">
<class name="Template" table="TEMPLATE">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="native" />
</id>
<property name="name" column="NAME" type="string" />
<one-to-one name="templateDefinition" class="com.reporttemplateengine.models.TemplateDefinition" constrained="true"></one-to-one>
</class>
</hibernate-mapping>
TemplateType.hbm.xml
<hibernate-mapping package="com.reporttemplateengine.models">
<class name="TemplateType" table="TEMPLATETYPE">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="native" />
</id>
<property name="name" column="NAME" type="string" />
</class>
</hibernate-mapping>
TemplateDefinition.hbm.xml
<hibernate-mapping package="com.reporttemplateengine.models">
<class name="TemplateDefinition" table="TEMPLATEDEFINITION">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="identity" />
</id>
<property name="templateFile" column="TEMPLATE_FILE" type="blob" />
<property name="version" column="VERSION" type="int" />
<property name="active" column="ACTIVE" type="int" />
<many-to-one name="template" class="com.reporttemplateengine.models.Template"
column="template_id" unique="true" not-null="true" cascade="all" />
<many-to-one name="templateType" class="com.reporttemplateengine.models.TemplateType"
column="template_type_id" unique="true" not-null="true" cascade="all" />
</class>
</hibernate-mapping>
When I call the API, Hibernate logs this query:
select
this_.ID as ID1_0_1_,
this_.NAME as NAME2_0_1_,
templatede2_.ID as ID1_1_0_,
templatede2_.TEMPLATE_FILE as TEMPLATE_FILE2_1_0_,
templatede2_.VERSION as VERSION3_1_0_,
templatede2_.ACTIVE as ACTIVE4_1_0_,
templatede2_.TEMPLATE_ID as TEMPLATE_ID5_1_0_,
templatede2_.TEMPLATE_TYPE_ID as TEMPLATE_TYPE_ID6_1_0_
from
SYSTEM.TEMPLATE this_
left outer join
SYSTEM.TEMPLATEDEFINITION templatede2_
on this_.ID=templatede2_.ID
It should actually look like this:
select
this_.ID as ID1_0_1_,
this_.NAME as NAME2_0_1_,
templatede2_.ID as ID1_1_0_,
templatede2_.TEMPLATE_FILE as TEMPLATE_FILE2_1_0_,
templatede2_.VERSION as VERSION3_1_0_,
templatede2_.ACTIVE as ACTIVE4_1_0_,
templatede2_.TEMPLATE_ID as TEMPLATE_ID5_1_0_,
templatede2_.TEMPLATE_TYPE_ID as TEMPLATE_TYPE_ID6_1_0_
from
SYSTEM.TEMPLATE this_
inner join
SYSTEM.TEMPLATEDEFINITION templatede2_
on this_.ID=templatede2_.TEMPLATE_ID
This is also missing the template type object nested in templateDefinition. I do not know how to achieve this.
Content is not allowed in trailling section. I copied declaration from a site and I used the model do apply on my own database
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.model.User" table="users">
<id column="ID_USER" name="id_user" type="java.lang.Integer"/>
<property column="ID_EMPL" name="id_empl" type="java.lang.Integer"/>
<property column="USERNAME" name="username" type="java.lang.String"/>
</class>
</hibernate-mapping>
Nevermind, this is fine:
<hibernate-mapping>
<class name="com.model.User" table="users">
<id column="ID_USER" name="id_user" type="java.lang.Integer"/>
<property column="ID_EMPL" name="id_empl" type="java.lang.Integer"/>
<property column="USERNAME" name="username" type="java.lang.String"/>
</class>
The configuration for Affiliate class is:
<class name="AffiliatesDO" table="AFFILIATES">
<id name="affiliateId" column="affiliate_id" type="java.lang.String">
<generator class="assigned" />
</id>
<property name="customerId" column="customer_id" type="int" />
<property name="affiliateType" column="affiliate_type" type="java.lang.String" />
<property name="site" column="site" type="java.lang.String" />
<property name="status" column="status" type="java.lang.String" />
<property name="createdBy" column="created_by" type="java.lang.String" />
<property name="creationDate" column="creation_date" type="java.util.Date" />
<property name="lastUpdatedBy" column="last_updated_by" type="java.lang.String" />
<property name="lastUpdated" column="last_updated" type="java.util.Date" />
<set name="address" lazy="true" inverse="true" order-by="address_id asc">
<key column="address_id"/>
<one-to-many class="AddressDO"/>
</set>
</class>
The Configuration for Address class is
<class name="Address"
table="Address">
<id name="addressId" column="address_id"
type="java.lang.String">
<generator class="assigned" />
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="address1" column="address1" type="java.lang.String" />
<property name="phone" column="phone" type="java.lang.String" />
<property name="landLineNumber" column="land_line_number" type="java.lang.String" />
<property name="faxNumber" column="fax_number" type="java.lang.String" />
</class>
I am getting the below error
org.hibernate.MappingException: Association references unmapped class: com.infibeam.customerservice.dbObjects.AddressDO
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2370)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2652)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1054)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.getConfiguration(AbstractComponentConfiguration.java:38)
at org.codehaus.mojo.hibernate3.HibernateExporterMojo.configureExporter(HibernateExporterMojo.java:186)
at org.codehaus.mojo.hibernate3.exporter.Hbm2JavaGeneratorMojo.configureExporter(Hbm2JavaGeneratorMojo.java:69)
Kindly show me the mistakes I have made.. I want to use one to many relation AffiliateDO->AddressDO
It looks like your mapping of the parent class is referring to AddressDO, but the subsequent child mapping is referring to Address (No "DO")... If I had to guess, you should change the second mapping to AddressDO (or visa versa). In any event, looks like a typo to me.
Considering Do as a typo error in Addrees xml, The Address mapping seems incorrect, there must address_id must be many-to-one currently it is generated new one.