读书人

一个新手关于hibernate 的有关问题 id

发布时间: 2012-02-21 16:26:23 作者: rapoo

一个新手关于hibernate 的问题 id" must match 郁闷啊!!
10:34:20,187 INFO Configuration: Reading mappings from resource: com/iustice/User.hbm.xml

10:34:20,250 ERROR XMLHelper: Error parsing XML: XML InputStream(7) The content of element type "id " must match "(meta*,column*,type?,generator?) ".

10:34:20,250 ERROR XMLHelper: Error parsing XML: XML InputStream(10) The content of element type "class " must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natu


<?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 package= "com.iustice ">
<class name= "User " table= "user ">
<id name= "id " column= "id ">
<generator class= "identity "> </generator>
</id>
<property name= "username " column= "username " unique= "true "/>
<property name= "password " column= "password " />
</class>
</hibernate-mapping>


<?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 ">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name= "connection.url "> jdbc:mysql://localhost/user </property>
<property name= "connection.driver_class "> org.gjt.mm.mysql.Driver </property>
<property name= "connection.username "> root </property>
<property name= "connection.password "> 002312708 </property>

<property name= "dialect "> org.hibernate.dialect.MySQLDialect </property>
<property name= "connection.pool_size "> 10 </property>
<property name= "current_session_context_class "> thread </property>
<property name= "cache.provider_class "> org.hibernate.cache.NoCacheProvider </property>
<property name= "show_sql "> true </property>
<!--
<property name= "hbm2ddl.auto "> create </property>
-->
<mapping resource= "com/iustice/User.hbm.xml " />


</session-factory>

</hibernate-configuration>


ublic class User implements Serializable {
private long id;


private String username;
private String password;
public User(){}
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public long getId(){
return id;
}
public void setId(long id){
this.id=id;
}


}


public class Login extends ActionForm {
private String password;
private String username;
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}

public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
/** @todo: finish this method, this is just the skeleton.*/
return null;
}

public void reset(ActionMapping actionMapping,
HttpServletRequest servletRequest) {


}
}


public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
NoSuchMethodException, InvocationTargetException,
IllegalAccessException {
String username=(String)PropertyUtils.getSimpleProperty(form, "username ");
String password=(String)PropertyUtils.getSimpleProperty(form, "password ");
Session s=HibernateUtil.currentionSession();
Query q=s.createQuery( "from User u where u.username= ' "+username+ " ' and password= ' "+password+ " ' ");
if(q.list().isEmpty()){
HibernateUtil.closeSession();
return(mapping.findForward( "loginfail "));
}
else{
HibernateUtil.closeSession();
request.getSession().setAttribute(username,username);
return mapping.findForward( "loginsuccess ");
}
}


}




[解决办法]
你的代码在我本地跑没有问题
估计又是文件编码格式的吧,你将xml文件的存储格式改为UTF-8试试
要是不行,我也没有办法了
[解决办法]
<generator class= "identity "> </generator>

改成 <generator class= "increment "> </generator>

试试.上次我也在这问题上载了很久,居然是这样.

读书人网 >Java Web开发

热点推荐