-->
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.  [ 3 posts ] 
Author Message
 Post subject: Validator does not create Schema Constraints in Postgres
PostPosted: Wed Oct 27, 2010 10:45 am 
Newbie

Joined: Tue Dec 18, 2007 9:01 pm
Posts: 3
Hello,

First of all my Versions I'm using:
Hibernate: 3.6.0.Beta2
HibernateAnnotations: 3.4.0.GA
HibernateValidator: 4.0.2.GA
Spring: 3.0.0.RELEASE
Postgres: 8.4-701.jdbc4

I'm playing around with Hibernate Validator and i encountered a problem while trying to generate schema constraints from validator annotations. I have the following Object to be validated:

Code:
@Entity
public class Abteilung extends AbstractPojo {

   @NotNull
   @Length(max = 10)
   private String   bezeichnung;
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer   id;
                [...getter and setter ommitted]


In my spring context which handles all hibernate objects (hibernate itself works fine by the way) i set the option to generate ddl constraints like that:

Code:
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="annotatedClasses">
         <list>
            <value>vereinsverwaltung.core.pojo.Abteilung</value>
            [...other mappings ommitted]
         </list>
      </property>
      <property name="hibernateProperties">
         <value>
            hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
            hibernate.hbm2ddl.auto=create
            [b]javax.persistence.validation.mode=ddl[/b]
      </value>
      </property>
   </bean>


When I now start my Application i can see the create logs in my console. But when i take a look in the database I cannot find any constraints:

Code:
CREATE TABLE abteilung
(
  id integer NOT NULL,
  bezeichnung character varying(255),
  CONSTRAINT abteilung_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);


Am I doing anything wrong?

Thank you for helping in advance,

Yours,
Mitschi


Top
 Profile  
 
 Post subject: Re: Validator does not create Schema Constraints in Postgres
PostPosted: Fri Oct 29, 2010 5:01 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

first off - HibernateAnnotations: 3.4.0.GA - is obsolete. In the Hibernate 3.6 version annotations are integrated in Hibernate Core so there is no need for an additional Annotations jar file. Not sure whether this causes the problem though. Setting javax.persistence.validation.mode=ddl is thr right thing to do provided you only want the DDL generation to occur and not actual validation. In the latter case you should use the mode AUTO.

Have you tried setting the hibernate logging level to debug to get some more information? Are there any exceptions?

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator does not create Schema Constraints in Postgres
PostPosted: Fri Oct 29, 2010 3:41 pm 
Newbie

Joined: Tue Dec 18, 2007 9:01 pm
Posts: 3
Hi,

thank you for your help! Obviously it was the jar problem. As I removed the validator dependency from the project and switched from hibernate to hibernate-core dependency it worked. At least i think so, because a length validator leads to an varchar(x) in the create script and even a not null constraint is added:

Code:
create table Abteilung (id int4 not null, bezeichnung varchar(10) not null [...]


Thank you again for helping!

Yours,
Mitschi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.