无法实例化默认的 tuplizer:HIbernate
Unable to instantiate default tuplizer: HIbernate
我已经编写了带有复合键的示例休眠应用程序,如下所示:
当我尝试 运行 应用程序创建 table 时出现以下错误。我是新来的冬眠者。谁能告诉我我在这里遗漏了什么。
Product.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">
<hibernate-mapping>
<class name="str.Product" table="products">
<composite-id name="id" class="Ptr">
<key-property name="productId" type="int">
<column name="productId" />
</key-property>
<key-property name="price" type="int">
<column name="Price" />
</key-property>
</composite-id>
<property name="proName" column="pname" length="10" />
</class>
Product.java
package str;
import javax.persistence.Transient;
public class Product implements java.io.Serializable{
private static final long serialVersionUID = 1L;
private Ptr id;
private String proName;
public void setProName(String proName)
{
this.proName = proName;
}
public String getProName()
{
return proName;
}
public Product(Ptr id, String proName) {
super();
this.id = id;
this.proName = proName;
}
public Product() {
}
public Ptr getId() {
return id;
}
public void setId(Ptr id) {
this.id = id;
}
}
Ptr.java
package str;
public class Ptr {
private int productId;
private double price;
public Ptr(){}
public Ptr(int productId, double price) {
super();
this.productId = productId;
this.price = price;
}
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
错误:
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:101)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:122)
at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:81)
at org.hibernate.mapping.Component.getType(Component.java:180)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
at org.hibernate.mapping.RootClass.validate(RootClass.java:271)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1358)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
at org .hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at com.cisco.common.ForOurLogic4Load.main(ForOurLogic4Load.java:14)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:98)
... 9 more
Caused by: org.hibernate.MappingException: component class not found: Ptr
at org.hibernate.mapping.Component.getComponentClass(Component.java:141)
at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:155)
at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:64)
at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:59)
... 14 more
Caused by: java.lang.ClassNotFoundException: Ptr
at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)`enter code here`
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:193)
at org.hibernate.mapping.Component.getComponentClass(Component.java:138)
... 17 more
您没有使用 class 的完整路径,您得到
java.lang.ClassNotFoundException: Ptr
请在您的映射文件中使用:
<composite-id name="id" class="str.Ptr">
我已经编写了带有复合键的示例休眠应用程序,如下所示: 当我尝试 运行 应用程序创建 table 时出现以下错误。我是新来的冬眠者。谁能告诉我我在这里遗漏了什么。
Product.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">
<hibernate-mapping>
<class name="str.Product" table="products">
<composite-id name="id" class="Ptr">
<key-property name="productId" type="int">
<column name="productId" />
</key-property>
<key-property name="price" type="int">
<column name="Price" />
</key-property>
</composite-id>
<property name="proName" column="pname" length="10" />
</class>
Product.java
package str;
import javax.persistence.Transient;
public class Product implements java.io.Serializable{
private static final long serialVersionUID = 1L;
private Ptr id;
private String proName;
public void setProName(String proName)
{
this.proName = proName;
}
public String getProName()
{
return proName;
}
public Product(Ptr id, String proName) {
super();
this.id = id;
this.proName = proName;
}
public Product() {
}
public Ptr getId() {
return id;
}
public void setId(Ptr id) {
this.id = id;
}
}
Ptr.java
package str;
public class Ptr {
private int productId;
private double price;
public Ptr(){}
public Ptr(int productId, double price) {
super();
this.productId = productId;
this.price = price;
}
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
错误:
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:101)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:122)
at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:81)
at org.hibernate.mapping.Component.getType(Component.java:180)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
at org.hibernate.mapping.RootClass.validate(RootClass.java:271)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1358)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
at org .hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at com.cisco.common.ForOurLogic4Load.main(ForOurLogic4Load.java:14)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:98)
... 9 more
Caused by: org.hibernate.MappingException: component class not found: Ptr
at org.hibernate.mapping.Component.getComponentClass(Component.java:141)
at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:155)
at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:64)
at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:59)
... 14 more
Caused by: java.lang.ClassNotFoundException: Ptr
at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)`enter code here`
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:193)
at org.hibernate.mapping.Component.getComponentClass(Component.java:138)
... 17 more
您没有使用 class 的完整路径,您得到
java.lang.ClassNotFoundException: Ptr
请在您的映射文件中使用:
<composite-id name="id" class="str.Ptr">