Dies ist meine erste Anwendung mit Hibernate, in diesem Programm habe ich eine JSP-Datei, während klicken Sie auf Senden Schaltfläche seinen Aufruf SaveServlet.java, und es erhalten die Werte aus dem Textfeld, aber während das Projekt ausgeführt wird Fehler, jemand bitte hilf mir.Hibernate, XML-Mapping-Problem
ERROR: HHH000196: Error parsing XML (40) : Element type "hibernate-mapping" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "default-cascade" must be declared for element type "hibernate-mapping".
ERROR: HHH000196: Error parsing XML (40) : Attribute "default-access" must be declared for element type "hibernate-mapping".
ERROR: HHH000196: Error parsing XML (40) : Attribute "default-lazy" must be declared for element type "hibernate-mapping".
ERROR: HHH000196: Error parsing XML (40) : Attribute "auto-import" must be declared for element type "hibernate-mapping".
ERROR: HHH000196: Error parsing XML (40) : Element type "class" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "table" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "mutable" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "polymorphism" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "dynamic-update" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "dynamic-insert" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "select-before-update" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Attribute "optimistic-lock" must be declared for element type "class".
ERROR: HHH000196: Error parsing XML (40) : Element type "id" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "id".
ERROR: HHH000196: Error parsing XML (40) : Attribute "column" must be declared for element type "id".
ERROR: HHH000196: Error parsing XML (40) : Attribute "type" must be declared for element type "id".
ERROR: HHH000196: Error parsing XML (40) : Element type "generator" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "class" must be declared for element type "generator".
ERROR: HHH000196: Error parsing XML (40) : Element type "property" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "column" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "type" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "unique" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "optimistic-lock" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "lazy" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "generated" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Element type "property" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "column" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "type" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "unique" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "optimistic-lock" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "lazy" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "generated" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Element type "property" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "column" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "type" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "unique" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "optimistic-lock" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "lazy" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "generated" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Element type "property" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "column" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "type" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "unique" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "optimistic-lock" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "lazy" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "generated" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Element type "property" must be declared.
ERROR: HHH000196: Error parsing XML (40) : Attribute "name" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "column" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "type" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "unique" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "optimistic-lock" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "lazy" must be declared for element type "property".
ERROR: HHH000196: Error parsing XML (40) : Attribute "generated" must be declared for element type "property".
" Error in SaveServlet org.hibernate.InvalidMappingException: Unable to read XML"
persistente Klasse User.java
import com.hiber.Bean
public class User {
private int id;
private String username,password,email,phone,city;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
und diese Zuordnungsdatei user.hbm
<hibernate-mapping>
<class name="User" table="user">
<id name="id" column="id" type="integer">
<generator class="assigned"></generator>
</id>
<property name="username" column="username" type="java.lang.String"></property>
<property name="password" column="password" type="java.lang.String"></property>
<property name="email" column="email" type="java.lang.String"></property>
<property name="phone" column="phone" type="java.lang.String"></property>
<property name="city" column="city" type="java.lang.String"></property>
</class>
</hibernate-mapping>
diese Konfigurationsdatei hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/brinkle?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">root</property>
<mapping resource="com/hiber/Bean/User.xml"/>
</session-factory>
</hibernate-configuration>
Dao Klassendatei UserDao.java
package com.hiber.Dao
public class UserDao {
Session session=NewHibernateUtil.getSessionFactory().openSession();
Transaction tran=session.beginTransaction();
public void addUser(String username,String password,String email,String phone,String city)
{
User user=new User();
user.setUsername(username);
user.setPassword(password);
user.setEmail(email);
user.setPhone(phone);
user.setCity(city);
session.save(user);
tran.commit();
System.out.println("saved succesfully");
}
}
HibernateUtil.java
public class NewHibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory()
{
if (sessionFactory == null) {
// loads configuration and mappings
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
// builds a session factory from the service registry
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
else
{
System.out.println("Session not created..........");
}
return sessionFactory;
}
}
das ist mein Servlet SaveServlet.java
package com.hiber.Controller;
import com.hiber.dao.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.HibernateException;
public class SaveServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username=request.getParameter("username");
String password =request.getParameter("password");
String email=request.getParameter("email");
String phone=request.getParameter("phone");
String city =request.getParameter("city");
System.out.println("the name is "+username+"pass is "+password+" emial is "+email +" phone is "+phone +" and city is "+city);
try
{
// System.out.println("here we go");
UserDao ud=new UserDao();
ud.addUser(username, password, email, phone, city);
RequestDispatcher rd=request.getRequestDispatcher("welcomeJSF.jsp");
rd.forward(request, response);
// response.sendRedirect("welcomeJSF.jsp");
}
catch(HibernateException e)
{
System.out.println("Error in SaveServlet "+e);
}
}
}
Haben Sie die ersten Zeilen in den Dateien '.cfg.xml' und' hbm.xml' weggelassen, oder ist das alles, was Sie haben? –
Xml version = "1.0" encoding = "UTF-8"?> Diese Zeilen? – Brinklesujin
Ja, können Sie Ihre Frage mit dem vollständigen Code aktualisieren, den Sie verwenden? Diese Header sind wichtig. –