Issue with <any>, same schema as above. I am recieving the following exception...
database MySQL (for this simple test I am using MySQL). so we have...
Code:
<any name="loctype" id-type="string" insert="false" update="false">
<meta-value value="LOCAL" class="Local" />
<meta-value value="INTERNATIONAL" class="International" />
<column name="loctype" />
<column name="id" />
</any>
When I change the loctype column value (databse value not mapping value) to "com.model.Local" it seems to work. I don't think that this was the intended use of <any> as the database would have to contain the classpath of the entity. Is Hibernate even using the value and class attribute values? In fact I can change the value and class attributes to anything and as long as the value in the database is "com.model.Local" Hibernate does not throw an exception and returns the correct object.
ExceptionCode:
This is a snippet of the exception, see below for the entire log print out.
org.hibernate.MappingException: Unknown entity: LOCAL
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:62)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:655)
at org.hibernate.type.AnyType.resolveAny(AnyType.java:111)
at org.hibernate.type.AnyType.resolve(AnyType.java:101)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.test.Main.main(Main.java:21)
SQL SchemasCode:
Removed columns not pertaining to problem, but local and international schemas are different.
Table Building (
pk(id);
varchar name;
varchar loctype;
)
Table Local (
pk(id);
varchar name;
)
Table International (
pk(id);
varchar name;
)
hibernate.cfg.xmlCode:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/acme</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<mapping resource="com/model/Building.hbm.xml"/>
<mapping resource="com/model/Local.hbm.xml"/>
<mapping resource="com/model/International.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Building.hbm.xmlCode:
<?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" >
<hibernate-mapping package="com.model">
<class name="Building" table="building">
<id name="id" column="id" type="integer">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string" not-null="true" />
<any name="loctype" id-type="string" insert="false" update="false">
<meta-value value="LOCAL" class="Local" />
<meta-value value="INTERNATIONAL" class="International" />
<column name="loctype" />
<column name="id" />
</any>
</class>
</hibernate-mapping>
Local.hbm.xmlCode:
<?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" >
<hibernate-mapping package="com.model">
<class name="Local" table="local">
<id name="building" column="id" type="integer">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string" not-null="true" />
</class>
</hibernate-mapping>
LoggingCode:
13:54:46,343 INFO Environment:464 - Hibernate 3.0.5
13:54:46,343 INFO Environment:477 - hibernate.properties not found
13:54:46,359 INFO Environment:510 - using CGLIB reflection optimizer
13:54:46,359 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
13:54:46,437 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
13:54:46,437 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
13:54:46,765 INFO Configuration:444 - Mapping resource: com/model/Building.hbm.xml
13:54:46,890 INFO HbmBinder:260 - Mapping class: com.model.Building -> building
13:54:46,906 INFO Configuration:444 - Mapping resource: com/model/Local.hbm.xml
13:54:46,937 INFO HbmBinder:260 - Mapping class: com.model.Local -> local
13:54:46,937 INFO Configuration:444 - Mapping resource: com/model/International.hbm.xml
13:54:46,968 INFO HbmBinder:260 - Mapping class: com.model.International -> international
13:54:46,968 INFO Configuration:1222 - Configured SessionFactory: null
13:54:46,968 INFO Configuration:875 - processing extends queue
13:54:46,984 INFO Configuration:879 - processing collection mappings
13:54:46,984 INFO Configuration:888 - processing association property references
13:54:46,984 INFO Configuration:917 - processing foreign key constraints
13:54:47,062 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
13:54:47,062 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
13:54:47,062 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
13:54:47,078 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/acme
13:54:47,078 INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
13:54:47,328 INFO SettingsFactory:77 - RDBMS: MySQL, version: 4.1.10a-nt
13:54:47,328 INFO SettingsFactory:78 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.10 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
13:54:47,359 INFO Dialect:92 - Using dialect: org.hibernate.dialect.MySQLDialect
13:54:47,359 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
13:54:47,375 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
13:54:47,375 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
13:54:47,375 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
13:54:47,375 INFO SettingsFactory:136 - JDBC batch size: 15
13:54:47,375 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
13:54:47,375 INFO SettingsFactory:144 - Scrollable result sets: enabled
13:54:47,375 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): enabled
13:54:47,375 INFO SettingsFactory:160 - Connection release mode: null
13:54:47,375 INFO SettingsFactory:184 - Maximum outer join fetch depth: 2
13:54:47,375 INFO SettingsFactory:187 - Default batch fetch size: 1
13:54:47,375 INFO SettingsFactory:191 - Generate SQL with comments: disabled
13:54:47,375 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
13:54:47,375 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
13:54:47,375 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
13:54:47,375 INFO SettingsFactory:203 - Query language substitutions: {}
13:54:47,375 INFO SettingsFactory:209 - Second-level cache: enabled
13:54:47,375 INFO SettingsFactory:213 - Query cache: disabled
13:54:47,375 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider
13:54:47,390 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
13:54:47,390 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
13:54:47,390 INFO SettingsFactory:257 - Echoing all SQL to stdout
13:54:47,390 INFO SettingsFactory:261 - Statistics: disabled
13:54:47,390 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled
13:54:47,390 INFO SettingsFactory:279 - Default entity-mode: pojo
13:54:47,531 INFO SessionFactoryImpl:152 - building session factory
13:54:47,546 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/eclipse/workspace/Hibernate/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
13:54:47,921 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
13:54:47,921 INFO SessionFactoryImpl:379 - Checking 0 named queries
Hibernate: select building0_.id as id, building0_.name as name0_, building0_.loctype as loctype0_, building0_.id as id0_ from building building0_
org.hibernate.MappingException: Unknown entity: LOCAL
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:62)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:655)
at org.hibernate.type.AnyType.resolveAny(AnyType.java:111)
at org.hibernate.type.AnyType.resolve(AnyType.java:101)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.test.Main.main(Main.java:21)