Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) - Unknown column 'A.createdDateTime' in 'order clause'
- org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acmy.AnotherClassC.classBset#975905b5-d59c-4e53-98dd-30cf39b0c831]
- @GenericGenerator(name = "system-uuid", strategy = "uuid")
- package db;
- import org.hibernate.annotations.GenericGenerator;
- package db;
- import java.io.Serializable;
- import java.util.Objects;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.Inheritance;
- import javax.persistence.InheritanceType;
- @Entity
- @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
- public class ClassA implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(generator = "system-uuid")
- private String id;
- private String value;
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getValue() {
- return value;
- }
- public void setValue(String value) {
- this.value = value;
- }
- @Override
- public int hashCode() {
- int hash = 7;
- hash = 67 * hash + Objects.hashCode(this.id);
- return hash;
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final ClassA other = (ClassA) obj;
- if (!Objects.equals(this.id, other.id)) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return "db.ClassA[ id=" + id.toString() + " ]";
- }
- }
- package db;
- import javax.persistence.DiscriminatorValue;
- import javax.persistence.Entity;
- @Entity
- @DiscriminatorValue("B")
- public class ClassB extends ClassA {
- private static final long serialVersionUID = 1L;
- @Override
- public String toString() {
- return "db.ClassB[ id=" + getId() + " ]";
- }
- }
- package db;
- import java.util.List;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityManagerFactory;
- import javax.persistence.Persistence;
- public class TestDb {
- EntityManager em;
- public static void main(String[] args) {
- new TestDb().start();
- }
- public void start() {
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("dbtest");
- em = emf.createEntityManager();
- em.getTransaction().begin();
- ClassA a = new ClassA();
- a.setValue("A");
- em.persist(a);
- a = new ClassA();
- a.setValue("B");
- em.persist(a);
- ClassB b = new ClassB();
- b.setValue("C");
- em.persist(b);
- em.getTransaction().commit();
- em.getTransaction().begin();
- List list = em.createQuery("from " + ClassA.class.getSimpleName() + " c order by c.value").getResultList();
- System.out.println("List " + list);
- em.getTransaction().commit();
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <persistence-unit name="dbtest" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>db.ClassA</class>
- <class>db.ClassB</class>
- <properties>
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:"/>
- <property name="javax.persistence.jdbc.user" value="app"/>
- <!--property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/-->
- <property name="javax.persistence.jdbc.password" value="app"/>
- <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
- <property name="javax.persistence.schema-generation.database.action" value="create"/>
- <property name="hibernate.hbm2ddl.auto" value="update"/>
- </properties>
- </persistence-unit>
- </persistence>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement