Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. @Entity
  2. @Table(name = "MyEntity")
  3. @org.hibernate.annotations.Table(appliesTo = "MyEntity")
  4. public class MyEntity
  5. {
  6. @Enumerated(value = javax.persistence.EnumType.STRING)
  7. @Transient
  8. @Formula(value = "select e.state from OTHER_ENTITY e")
  9. private State state;
  10.  
  11. public State getState()
  12. {
  13. return this.state;
  14. }
  15. //setter and another properties
  16. }
  17.  
  18. <persistence 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"
  19. version="2.0">
  20. <persistence-unit name="myPersistence" transaction-type="RESOURCE_LOCAL">
  21. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  22. <mapping-file>META-INF/orm.xml</mapping-file>
  23. <exclude-unlisted-classes>true</exclude-unlisted-classes>
  24. <properties>
  25. <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
  26. <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
  27. <property name="hibernate.connection.url" value="jdbc:mysql://url:3306/db" />
  28. <property name="hibernate.connection.username" value="root" />
  29. <property name="hibernate.connection.password" value="root" />
  30. <property name="hibernate.show_sql" value="true" />
  31. <property name="hibernate.hbm2ddl.auto" value="validate" />
  32. </properties>
  33. </persistence-unit>
  34.  
  35. @Entity
  36. @Table(name = "MyEntity")
  37. @org.hibernate.annotations.Table(appliesTo = "MyEntity")
  38. public class MyEntity
  39. {
  40. // MAYBE YOU HAVE TO MOVE IT TO THE GETTER @Enumerated(value = javax.persistence.EnumType.STRING)
  41. // REMOVE THIS @Transient
  42. private State state;
  43.  
  44. @Enumerated(value = javax.persistence.EnumType.STRING) // MOVED
  45. @Formula(value = "(select e.state from OtheEntity e)")
  46. public State getState()
  47. {
  48. return this.state;
  49. }
  50. //setter and another properties
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement