Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. '"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6. <session-factory>
  7. <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
  8. <property name="hibernate.connection.password">65065827</property>
  9. <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
  10. <property name="hibernate.connection.username">root</property>
  11. <property name="hibernate.default_schema">vincent</property>
  12. <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
  13. <property name="hibernate.current_session_context_class">thread</property>
  14. <property name="hibernate.show_sql">true</property>
  15. <property name="hibernate.jdbc.use_streams_for_binary">false</property>
  16.  
  17.  
  18. <mapping class="pa.Tesdb" />
  19.  
  20. </session-factory>
  21.  
  22. package pa;
  23.  
  24. import org.hibernate.*;
  25. import org.hibernate.cfg.*;
  26.  
  27. public class HibernateUtil {
  28. private static final SessionFactory sessionFactory = new AnnotationConfiguration()
  29. .configure("/pa/hibernate1.cfg.xml").buildSessionFactory();
  30.  
  31. public static SessionFactory getSessionFactory() {
  32. return sessionFactory;
  33. }
  34. }
  35.  
  36. **tesdb.java** ( tesdb.java was generated by JBOSS TOOLS )
  37.  
  38. package pa;
  39.  
  40. import javax.persistence.Column;
  41. import javax.persistence.Entity;
  42. import javax.persistence.Id;
  43. import javax.persistence.Table;
  44.  
  45. /**
  46. * Tesdb generated by hbm2java
  47. */
  48. @Entity
  49. @Table(name = "tesdb", catalog = "test")
  50. public class Tesdb implements java.io.Serializable {
  51.  
  52. private int idtesdb;
  53. private String tesdbcol;
  54.  
  55. public Tesdb() {
  56. }
  57.  
  58. public Tesdb(int idtesdb) {
  59. this.idtesdb = idtesdb;
  60. }
  61.  
  62. public Tesdb(int idtesdb, String tesdbcol) {
  63. this.idtesdb = idtesdb;
  64. this.tesdbcol = tesdbcol;
  65. }
  66.  
  67. @Id
  68. @Column(name = "idtesdb", unique = true, nullable = false)
  69. public int getIdtesdb() {
  70. return this.idtesdb;
  71. }
  72.  
  73. public void setIdtesdb(int idtesdb) {
  74. this.idtesdb = idtesdb;
  75. }
  76.  
  77. @Column(name = "tesdbcol", length = 45)
  78. public String getTesdbcol() {
  79. return this.tesdbcol;
  80. }
  81.  
  82. public void setTesdbcol(String tesdbcol) {
  83. this.tesdbcol = tesdbcol;
  84. }
  85.  
  86. }
  87.  
  88. package pa;
  89.  
  90. import java.io.IOException;
  91. import java.io.PrintWriter;
  92. import java.util.List;
  93.  
  94. import javax.persistence.Query;
  95. import javax.servlet.ServletException;
  96. import javax.servlet.annotation.WebServlet;
  97. import javax.servlet.http.HttpServlet;
  98. import javax.servlet.http.HttpServletRequest;
  99. import javax.servlet.http.HttpServletResponse;
  100. import javax.transaction.UserTransaction;
  101.  
  102. import org.hibernate.Session;
  103. import org.hibernate.Transaction;
  104.  
  105. import pa.HibernateUtil;
  106. import pa.Tesdb;
  107.  
  108. /**
  109. * Servlet implementation class Testing
  110. */
  111. @WebServlet("/Testing")
  112. public class Testingg extends HttpServlet {
  113. private static final long serialVersionUID = 1L;
  114.  
  115. /**
  116. * @see HttpServlet#HttpServlet()
  117. */
  118. public Testingg() {
  119. super();
  120. // TODO Auto-generated constructor stub
  121. }
  122.  
  123. /**
  124. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  125. */
  126. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  127. // TODO Auto-generated method stub
  128. response.setContentType("text/html");
  129. Session session = HibernateUtil.getSessionFactory().getCurrentSession();
  130. Transaction Tx = session.beginTransaction();
  131. List intro = session.createQuery("FROM Tesdb").list();
  132. PrintWriter out = response.getWriter();
  133. out.println( "Run End" );
  134. out.println( intro.size() );
  135. Tx.commit();
  136. }
  137.  
  138. /**
  139. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  140. */
  141. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  142. // TODO Auto-generated method stub
  143. }
  144.  
  145. }
  146.  
  147. Table: tesdb
  148. Columns:
  149. idtesdb int(11) PK
  150. tesdbcol varchar(45)
  151.  
  152. Hibernate:
  153. select
  154. tesdb0_.idtesdb as idtesdb1_0_,
  155. tesdb0_.tesdbcol as tesdbcol2_0_
  156. from test.vincent.tesdb tesdb0_
  157.  
  158. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.tesdb tesdb0_' at line 1
  159. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  160. sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  161. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  162. .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement