I try to put some Objects in my MySql Database but I am stuck with the
org.hibernate.MappingException: Could not resolve named type : String
I tried to isolate the code which throws the exception and it seems there is a problem with my hbm.xml files.
- It throws the exception when I comment out the actual transaction which means data should not be the problem.
- If I comment out all mapping sources and transactions there is no exception.
- Comment out all but one mapping source it throws the exception (tried it with all sourcess).
- I checked, all files are UTF-8 encoding.
Of course I will provide more code if you need it. Those are xml files I use:
*hibernate log *
Exception in thread "main" org.hibernate.MappingException: Could not resolve named type : String
at org.hibernate.mapping.BasicValue.interpretExplicitlyNamedType(BasicValue.java:709)
at org.hibernate.mapping.BasicValue.buildResolution(BasicValue.java:402)
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:314)
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:304)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.lambda$processValueResolvers$4(InFlightMetadataCollectorImpl.java:1800)
at java.base/java.util.ArrayList.removeIf(ArrayList.java:1682)
at java.base/java.util.ArrayList.removeIf(ArrayList.java:1660)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processValueResolvers(InFlightMetadataCollectorImpl.java:1799)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1785)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:331)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:128)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:451)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:910)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:960)
at problem.Insert.main(Insert.java:39)
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">XXX</property>
<property name="hibernate.connection.password">XXX</property>
<property name="hibernate.connection.url">XXX</property>
<property name="hibernate.connection.username">XXX</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<mapping resource = "Alien.hbm.xml" />
<mapping resource = "AlienFood.hbm.xml" />
<mapping resource = "AlienSpaceship.hbm.xml" />
</session-factory>
</hibernate-configuration>
Alien.hbm.xml
<?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>
<class name="problem.Alien" table="alien">
<meta attribute="class description">
</meta>
<id name="aid" type="int" column="aid">
<generator class="native" />
</id>
<property name="acolour" column="acolour" type="String" />
<many-to-one name="spaceships" column="spaceship_sID"
class="problem.AlienSpaceship" />
</class>
</hibernate-mapping>
AlienFood.hbm.xml
<?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>
<class name="problem.AlienFood" table="alienfood">
<meta attribute="class description">
</meta>
<id name="fid" type="int" column="fid">
<generator class="native" />
</id>
<property name="fname" column="fname" type="String" />
<set name="aliens" cascade="save-update"
table="alien_alienfood">
<key column="aid" />
<many-to-many column="aid" class="problem.Alien" />
</set>
</class>
</hibernate-mapping>
AlienSpaceship.hbm.xml
<?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>
<class name="problem.AlienSpaceship" table="alienspaceship">
<meta attribute="class description">
</meta>
<id name="sID" type="int" column="sID">
<generator class="native" />
</id>
<property name="sName" column="sName" type="String" />
<property name ="sCooless" column="sCoolness" type="String" />
</class>
</hibernate-mapping>