Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
  2.  
  3. new Unit().getBy(3L);
  4.  
  5. @MappedSuperclass
  6. public abstract class Generic<T extends Generic> {
  7. @Transient
  8. public Class<T> entityClass;
  9. Generic() {
  10. entityClass = ((Class) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
  11. }
  12. @Id
  13. @GeneratedValue(strategy = GenerationType.TABLE)
  14. public Long id;
  15.  
  16. public T getBy(Long id) {
  17. return JPA.em().find(entityClass, id);
  18. }
  19.  
  20. @MappedSuperclass
  21. public abstract class GenericDictionary<T extends Generic<T>> extends Generic<T> {
  22.  
  23. @Required
  24. public String name;
  25. @Required
  26. public boolean active = true;
  27.  
  28. public String getName() {
  29. return name;
  30. }
  31.  
  32. public void setName(String name) {
  33. this.name = name;
  34. }
  35.  
  36. public boolean getActive() {
  37. return active;
  38. }
  39.  
  40. public void setActive(boolean stat) {
  41. this.active = stat;
  42. }
  43.  
  44. @Entity
  45. @Table(name="common__Unit")
  46. public class Unit extends GenericDictionary<Unit> {
  47. @ManyToOne(fetch=FetchType.LAZY)
  48. @JoinColumn(name="parent_id")
  49. public Unit parent;
  50. }
  51.  
  52. new Unit().getBy(3L);
  53.  
  54. @Entity
  55. @Table(name="common__Clinic")
  56. public class Clinic extends GenericDictionary<Clinic> {
  57. @ManyToMany(cascade = CascadeType.PERSIST)
  58. public List<Unit> unit;
  59.  
  60. Clinic clinic = new Clinic().getBy(3L);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement