These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate don't read property annotations
PostPosted: Sun Jan 31, 2010 11:22 pm 
Newbie

Joined: Wed Jun 10, 2009 5:11 pm
Posts: 4
Good day,

I've reached a strange problem, after I updated my classes to extend another mappedsuperclass, hibernate annotation doesn't reads annotations on the properties, only when I move annotationsto the getters - it reads. Any idea?

It appears with following error (for example):
Quote:
org.hibernate.AnnotationException: Unable to create unique key constraint (id_pol, year, x_vozrast) on table t_smertnosti: id_pol, x_vozrast not found
at org.hibernate.cfg.AnnotationConfiguration.buildUniqueKeyFromColumnNames(AnnotationConfiguration.java:616)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:348)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:301)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)



where t_smertnosti is defined in:
Code:
@Entity
@Table(name = "t_smertnosti", schema = "program_engine", uniqueConstraints = { @UniqueConstraint(columnNames = {
        "id_pol", "year", "x_vozrast" }) })
@Audited
@Indexed
public class TSmertnosti extends AbstractUniqaDocument {

    @JoinColumn(name = "id_pol", referencedColumnName = "id", nullable = false)
    @ManyToOne(targetEntity = SprPol.class)
    @NotNull
    private SprPol pol;

    @JoinColumn(name = "year", nullable = false, referencedColumnName = "id")
    @ManyToOne(targetEntity = SprYear.class)
    @NotNull
    private SprYear year;
    @Column(name = "x_vozrast", nullable = false, scale = 10, precision = 20)
    @NotNull
    private Double xVozrast;

    @Column(name = "lx", scale = 10, precision = 20)
    private Double lx;
    @Column(name = "dx", scale = 10, precision = 20)
    private Double dx;
    @Column(name = "com_d", scale = 10, precision = 20)
    private Double comD;
    @Column(name = "com_c", scale = 10, precision = 20)
    private Double comC;
    @Column(name = "com_n", scale = 10, precision = 20)
    private Double comN;
    @Column(name = "com_m", scale = 10, precision = 20)
    private Double comM;

    //..... getters-setters ....
}


and AbstractUniqaDocument (I've already moved the annotations to the getters) :
Code:
@MappedSuperclass
@Audited
@Indexed
@TypeDef( name="UUIDUserType", typeClass = UUIDUserType.class)
public class AbstractUniqaDocument implements Serializable {

   private static final long serialVersionUID = -2004637495147973726L;

    private String id = UUID.randomUUID().toString();

    private String cod1c;

    private Boolean couldBeExportedTo1C;

    private SprLic author;
   
   private Date creationDate = new Date();
   
   private Long version;


    public AbstractUniqaDocument() {
    }

   
    @Id
   @Type(type="UUIDUserType")
    @Column(name = "id")
    @DocumentId
    public String getId() {
      return id;
   }

   public void setId(String id) {
      this.id = id;
   }

   
   @Column(name = "cod_1c")
    @Field
    public String getCod1c() {
        return cod1c;
    }

    public void setCod1c(String cod1c) {
        this.cod1c = cod1c;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (!(o instanceof AbstractUniqaDocument))
            return false;

        AbstractUniqaDocument that = (AbstractUniqaDocument) o;

        if (!id.equals(that.id))
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Column(name = "could_be_exported_to_1c")
    @Field
    public Boolean getCouldBeExportedTo1C() {
        return couldBeExportedTo1C;
    }

    public void setCouldBeExportedTo1C(Boolean couldBeExportedTo1C) {
        this.couldBeExportedTo1C = couldBeExportedTo1C;
    }
   

   @PrePersist
   public void prePersist() {
      if (getAuthor() == null) {

         Identity identity = (Identity )org.jboss.seam.Component.getInstance("org.jboss.seam.security.identity");
         if (identity != null) {
            String principalName = identity.getPrincipal().getName();
            
            EntityManager entityManager = (EntityManager)org.jboss.seam.Component.getInstance("entityManager");
            Query q = entityManager.createNamedQuery("UserAccount.byUsername");
            q.setParameter("username", principalName);
            UserAccount account = (UserAccount )q.getSingleResult();
            
            this.setAuthor(account.getContragent());
         }
      }
   }

   @JoinColumn(name="id_author", referencedColumnName="id")
    @ManyToOne(targetEntity=SprLic.class, fetch=FetchType.LAZY)
    public SprLic getAuthor() {
      return author;
   }

   public void setAuthor(SprLic author) {
      this.author = author;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name="creation_date")
   public Date getCreationDate() {
      return creationDate;
   }

   public void setCreationDate(Date creationDate) {
      this.creationDate = creationDate;
   }

   @Version
    @Column(name="opt_lock_version")
    public Long getVersion() {
      return version;
   }

   public void setVersion(Long version) {
      this.version = version;
   }
   
   
}


Any idea about this error?

Regards,

Ilya Dyoshin


Top
 Profile  
 
 Post subject: Re: Hibernate don't read property annotations
PostPosted: Mon Feb 01, 2010 7:59 am 
Newbie

Joined: Wed Jun 10, 2009 5:11 pm
Posts: 4
solved this by moving all annotations to the fields, and adding additional annotation to the classes @AccessMethod("field")

Really strange problem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.