2

Basing on documentation, I appended the fetch-profile inside class. It doesn't validate and I don't know why.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.mycompany.nncloudrestservice.model">
  <class name="User" table="users">
    <meta attribute="class-description">
        Description under construction
    </meta>
    <id name="id" type="int">
        <column name="id_user" not-null="true"/>
        <generator class="native"/>
    </id>
    <property name="login" column="login" type="string"/>
    <property name="email" column="email" type="string"/>
    <property name="password" column="password" type="string"/>
    <property name="activated" column="activated" type="boolean"/> 
    <property name="info_to_admin" column="info_to_admin" type="string"/>
    <property name="session_id" column="session_id" type="string"/>
    <property name="registered" column="registered" type="date"/>
    <bag name="networks" cascade="all" table="networks" inverse="true" lazy="true">
        <key column="id_user" not-null="true"/>
        <one-to-many class="Network"/>
    </bag>
    <fetch-profile name="user-with-networks">
      <fetch association="networks" style="join"/>
    </fetch-profile>
    <one-to-one name="performance_settings" cascade="all" class="PerformanceSettings"></one-to-one>
  </class>
</hibernate-mapping>

Validation result:

Element type "fetch-profile" must be declared. [23] 
Element type "fetch" must be declared. [24] 
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*,resultset*,(query|sql-query)*)". [27] 

Totally odd thing, especially after discovering that the fetch-profile is explicitly declared in DTD:

<!ELEMENT class (
    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)*
)>
0x6B6F77616C74
  • 2,559
  • 7
  • 38
  • 65
  • What are you using to validate? The content model in the validation result doesn't match the DTD, so it seems like the public identifier is getting resolved to a different DTD. Is there any additional stack trace you could post? – Daniel Haley Oct 05 '15 at 16:23
  • @DanielHaley I used default netbeans validator and some online tools, where the result is exactly the same. How to obtain additional stack trace? – 0x6B6F77616C74 Oct 05 '15 at 16:47
  • Are you sure the error messages are exactly the same? If the DTD specified in the system identifier is used (http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd) you will still get errors, but it's because `one-to-one` needs to come before `fetch-profile`. (Try swapping it and validating in one of your online tools again.) – Daniel Haley Oct 05 '15 at 17:00
  • @DanielHaley Tried it and nothing changed, as well as after moving fetch-profile outside class. – 0x6B6F77616C74 Oct 05 '15 at 17:12
  • Did you try `session.enableFetchProfile("user-with-networks");` before your operations? – Channa Jayamuni Oct 10 '15 at 17:41
  • @ChannaJayamuni Yes, but it doesn't matter. There is no association between code and XML validation. – 0x6B6F77616C74 Oct 10 '15 at 18:10

1 Answers1

2

The fetch profile feature was introduced with Hibernate 3.5. Prior to that the DTD did not contain this tag. Chances are very high that your validator catches an outdated version. As per this solution here you should take care that no 3.0 jars are on the class path. You also might want to set SGML_CATALOG_FILES (see here) to a local copy of the DTD just for testing further changes.

Community
  • 1
  • 1
yacc
  • 2,915
  • 4
  • 19
  • 33