-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: net.sf.hibernate.MappingException
PostPosted: Tue Jul 18, 2006 11:08 pm 
Newbie

Joined: Tue Jul 18, 2006 10:52 pm
Posts: 6
信息: Mapping resource: com/jl165/bean/AdverBean.hbm.xml
2006-7-19 11:01:25 net.sf.hibernate.cfg.Configuration add
严重: Could not compile the mapping document
net.sf.hibernate.MappingException: persistent class [AdverBean] not found
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:84)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1229)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:333)
at com.jl165.DAO.DefaultDAO.action(DefaultDAO.java:32)
at com.jl165.DAO.ConnectionTest.main(ConnectionTest.java:37)

the above is my question,for what ,this exception is happend,everybody who can give me a answer!!!

the following is my code:
===========
package com.jl165.bean;

import java.sql.*;

public class AdverBean {

private int adverID; //广告标识号,只提供查询

private String adverName; //广告公司的名字

private String adverBackType; //广告反馈到用户手机上信息的形式

private String filePath; //广告文件存放的路径

private String adverMessage; //群发广告语

private int adverCost; //广告费用

private Date adverPublicTime; //广告发布时间

private int adverLastTime; //广告持续时间,按天填写

private String adverTelephone; //广告商联系电话

private String adverManTelephone;//广告商联系人电话,建议为移动电话

private String adverAddress; //广告公司具体地址

private String backtime; //广告语下发的时段

private String state; //标识广告发布状态,第一次注册后的状态是off

private String FHFtime; //网站上发布返话费的时间段,需要商户购买

/**
* @return Returns the state.
*/
public String getState() {
return state;
}

/**
* @param state
* The state to set.
*/
public void setState(String state) {
this.state = state;
}

public AdverBean() {
}

public int getAdverCost() {
return adverCost;
}

public int getAdverLastTime() {
return adverLastTime;
}

public String getAdverName() {
return adverName;
}

public String getAdverMessage() {
return adverMessage;
}

public Date getAdverPublicTime() {
return adverPublicTime;
}

public String getFilePath() {
return filePath;
}

public int getAdverID() {
return adverID;
}

public String getAdverAddress() {
return adverAddress;
}

public String getAdverBackType() {
return adverBackType;
}

public String getAdverManTelephone() {
return adverManTelephone;
}

public String getAdverTelephone() {
return adverTelephone;
}

public String getBacktime() {
return backtime;
}

public void setAdverCost(int adverCost) {
this.adverCost = adverCost;
}

public void setAdverLastTime(int adverLastTime) {
this.adverLastTime = adverLastTime;
}

public void setAdverMessage(String adverMessage) {
this.adverMessage = adverMessage;
}

public void setAdverName(String adverName) {
this.adverName = adverName;
}

public void setAdverPublicTime(Date adverPublicTime) {
this.adverPublicTime = adverPublicTime;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}

public void setAdverAddress(String adverAddress) {
this.adverAddress = adverAddress;
}

public void setAdverBackType(String adverBackType) {
this.adverBackType = adverBackType;
}

public void setAdverManTelephone(String adverManTelephone) {
this.adverManTelephone = adverManTelephone;
}

public void setAdverTelephone(String adverTelephone) {
this.adverTelephone = adverTelephone;
}

public void setBacktime(String backtime) {
this.backtime = backtime;
}

/**
* @return Returns the fHFtime.
*/
public String getFHFtime() {
return FHFtime;
}

/**
* @param ftime
* The fHFtime to set.
*/
public void setFHFtime(String ftime) {
FHFtime = ftime;
}
}
==============
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="AdverBean" table="ADVERTABLE_ZL">

<id name="adverID" type="int" column="ADVERID" unsaved-value="null" >
<generator class="increment" />
</id>

<property name="adverName" type="string">
<column name="ADVERNAME" length="20" not-null="true"/>
</property>

<property name="adverBackType" type="string">
<column name="ADVERBACKTYPE" length="10" not-null="true"/>
</property>

<property name="filePath" type="string">
<column name="ADVERPATH" length="40" not-null="true"/>
</property>

<property name="adverMessage" type="string">
<column name="ADVERMESSAGE" length="70" not-null="true"/>
</property>

<property name="adverCost" type="int">
<column name="ADVERCOST" length="10" not-null="true"/>
</property>

<property name="adverPublicTime" type="java.sql.Date">
<column name="ADVERPUBLICTIME" sql-type="date" not-null="true"/>
</property>

<property name="adverLastTime" type="int">
<column name="ADVERLASTTIME" length="10" not-null="true"/>
</property>

<property name="adverTelephone" type="string">
<column name="ADVERTELEPHONE" length="20" not-null="true"/>
</property>

<property name="adverManTelephone" type="string">
<column name="ADVERMANTELEPHONE" length="20" not-null="true"/>
</property>

<property name="adverAddress" type="string">
<column name="ADVERADDRESS" length="40" not-null="true"/>
</property>

<property name="backtime" type="string">
<column name="BACKTIME" length="20" not-null="true"/>
</property>

<property name="state" type="string">
<column name="BACKUSE1" length="20" not-null="true"/>
</property>

<property name="FHFtime" type="string">
<column name="BACKUSE2" length="20" not-null="true"/>
</property>
</class>

</hibernate-mapping>
================
package com.jl165.DAO;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.Query;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import java.util.*;

import com.jl165.bean.AdverBean;

public class DefaultDAO {

public DefaultDAO() {
}

//配置文件
private static Configuration config = null;

//list,查询数据都保存在这里
private static List beanList = null;

//需要执行的查询语句
private String sqlString = null;

/*
* action方法通过两个参数确定执行什么养的操作。
*/
public void action(AdverBean adver, String operation) {
try {
//AdverBean adver = (AdverBean)object;
config = new Configuration().addClass(adver.getClass());
System.out.println("configure is right");
SessionFactory sessions = config.buildSessionFactory();
Session session = sessions.openSession();

Transaction action = session.beginTransaction();

if ("save".equals(operation)) {
session.save(adver);
} else if ("updata".equals(operation)) {
session.update(adver);
} else if ("delete".equals(operation)) {
session.delete(adver);
} else if ("insert".equals(operation)) {
session.save(adver);
} else if ("find".equals(operation)) {
Query query = session.createQuery(sqlString);
beanList = query.list();
}

action.commit();
session.close();
sessions.close();
} catch (Exception e) {
e.printStackTrace();
}

}

/**
* @return Returns the beanList.
*/
public static List getBeanList() {
return beanList;
}

/**
* @param sqlString
* The sqlString to set.
*/
public void setSqlString(String sqlString) {
this.sqlString = sqlString;
}
}



================

everybody please give me a help,thank you,and answer me in my e-mail

[url]13364477670@cumail.com.cn[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 12:42 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Include "'package" in your <class> defintion. Basically Hibernate is trying to search for "AdverBean" instead of "com.jl165.bean.AdverBean". Try giving:

Code:
<hibernate-mapping>

<class [b]package="com.jl165.bean"[/b] name="AdverBean" table="ADVERTABLE_ZL">


...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 9:46 pm 
Newbie

Joined: Tue Jul 18, 2006 10:52 pm
Posts: 6
i modify my code as you tell me,but there aslo has a exception following:

信息: Mapping resource: com/jl165/bean/AdverBean.hbm.xml
2006-7-20 9:19:27 net.sf.hibernate.util.XMLHelper$ErrorLogger error
严重: Error parsing XML: XML InputStream(8) Attribute names must not start with "[" characters.
2006-7-20 9:19:27 net.sf.hibernate.cfg.Configuration addInputStream
严重: Could not configure datastore from input stream
org.dom4j.DocumentException: Error on line 8 of document : Attribute names must not start with "[" characters. Nested exception: Attribute names must not start with "[" characters.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)

why?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 2:38 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Formatting issue in my earlier reply. Try this:

hibernate-mapping>

Code:
<class package="com.jl165.bean" name="AdverBean" table="ADVERTABLE_ZL">


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.