Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) - Unknown column 'A.createdDateTime' in 'order clause'
  2. org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acmy.AnotherClassC.classBset#975905b5-d59c-4e53-98dd-30cf39b0c831]
  3.  
  4. @GenericGenerator(name = "system-uuid", strategy = "uuid")
  5. package db;
  6.  
  7. import org.hibernate.annotations.GenericGenerator;
  8.  
  9. package db;
  10.  
  11. import java.io.Serializable;
  12. import java.util.Objects;
  13. import javax.persistence.Entity;
  14. import javax.persistence.GeneratedValue;
  15. import javax.persistence.Id;
  16. import javax.persistence.Inheritance;
  17. import javax.persistence.InheritanceType;
  18.  
  19. @Entity
  20. @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  21. public class ClassA implements Serializable {
  22. private static final long serialVersionUID = 1L;
  23.  
  24. @Id
  25. @GeneratedValue(generator = "system-uuid")
  26. private String id;
  27.  
  28. private String value;
  29.  
  30. public String getId() {
  31. return id;
  32. }
  33.  
  34. public void setId(String id) {
  35. this.id = id;
  36. }
  37.  
  38. public String getValue() {
  39. return value;
  40. }
  41.  
  42. public void setValue(String value) {
  43. this.value = value;
  44. }
  45.  
  46. @Override
  47. public int hashCode() {
  48. int hash = 7;
  49. hash = 67 * hash + Objects.hashCode(this.id);
  50. return hash;
  51. }
  52.  
  53. @Override
  54. public boolean equals(Object obj) {
  55. if (obj == null) {
  56. return false;
  57. }
  58. if (getClass() != obj.getClass()) {
  59. return false;
  60. }
  61. final ClassA other = (ClassA) obj;
  62. if (!Objects.equals(this.id, other.id)) {
  63. return false;
  64. }
  65. return true;
  66. }
  67.  
  68. @Override
  69. public String toString() {
  70. return "db.ClassA[ id=" + id.toString() + " ]";
  71. }
  72. }
  73.  
  74. package db;
  75.  
  76. import javax.persistence.DiscriminatorValue;
  77. import javax.persistence.Entity;
  78.  
  79. @Entity
  80. @DiscriminatorValue("B")
  81. public class ClassB extends ClassA {
  82. private static final long serialVersionUID = 1L;
  83.  
  84. @Override
  85. public String toString() {
  86. return "db.ClassB[ id=" + getId() + " ]";
  87. }
  88. }
  89.  
  90. package db;
  91.  
  92. import java.util.List;
  93. import javax.persistence.EntityManager;
  94. import javax.persistence.EntityManagerFactory;
  95. import javax.persistence.Persistence;
  96.  
  97. public class TestDb {
  98. EntityManager em;
  99.  
  100. public static void main(String[] args) {
  101. new TestDb().start();
  102. }
  103.  
  104. public void start() {
  105. EntityManagerFactory emf = Persistence.createEntityManagerFactory("dbtest");
  106. em = emf.createEntityManager();
  107. em.getTransaction().begin();
  108. ClassA a = new ClassA();
  109. a.setValue("A");
  110. em.persist(a);
  111. a = new ClassA();
  112. a.setValue("B");
  113. em.persist(a);
  114. ClassB b = new ClassB();
  115. b.setValue("C");
  116. em.persist(b);
  117. em.getTransaction().commit();
  118.  
  119. em.getTransaction().begin();
  120. List list = em.createQuery("from " + ClassA.class.getSimpleName() + " c order by c.value").getResultList();
  121. System.out.println("List " + list);
  122. em.getTransaction().commit();
  123. }
  124. }
  125.  
  126. <?xml version="1.0" encoding="UTF-8"?>
  127. <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  128. <persistence-unit name="dbtest" transaction-type="RESOURCE_LOCAL">
  129. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  130. <class>db.ClassA</class>
  131. <class>db.ClassB</class>
  132. <properties>
  133. <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:"/>
  134. <property name="javax.persistence.jdbc.user" value="app"/>
  135. <!--property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/-->
  136. <property name="javax.persistence.jdbc.password" value="app"/>
  137. <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
  138. <property name="javax.persistence.schema-generation.database.action" value="create"/>
  139. <property name="hibernate.hbm2ddl.auto" value="update"/>
  140. </properties>
  141. </persistence-unit>
  142. </persistence>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement