-->
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: GENERATING SEQUENCES and PostgreSQL Schemas
PostPosted: Sun Feb 22, 2009 12:26 am 
Newbie

Joined: Sat Feb 21, 2009 12:30 am
Posts: 7
I don't need help, but am just making an observation.
This is a continuation of the Topic I found on this problem:
GENERATING SEQUENCES


I have a PostgreSQL database with several Schemas. The reason for the different Schemas is that PostgreSQL will allow me to define the specific location of the various Schemas (which Linux or Hard Drive partition I have them on), but no matter.

I have a schema called stocks under my PostgreSQL database. I have my stock information and ticker information in that schema.

When I initially tried to save records to a table in that schema, I was getting an exception stating that the hibernate_sequence could not be found. This is even though I had defined it in that schema. This seemed odd, since in my previous tests with tables in the public schema of another database, there had been no problem.

So, I created an hibernate_sequence under the public schema of this database.

Low and behold it worked!!!! BUT!!!! I did not want to use a sequence in the public schema. I wanted it under the stocks schema.

So, I created a sequence called exchangeid_seq under my stocks schema AND used a modified Exchange.hbm.xml file that defined the generator like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 21, 2009 9:30:23 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
  <class name="org.scawa.stockandtrade.pojo.Exchange" schema="stocks" table="exchange">
    <id name="id" type="int">
      <column name="id"/>
      <generator class="sequence">
          <param name="sequence">stocks.exchangeid_seq</param>
      </generator>
    </id>
    <property name="name" type="string">
      <column length="10" name="name" not-null="true"/>
    </property>
    <property name="description" type="string">
      <column length="60" name="description"/>
    </property>
    <property name="dateCreated" type="timestamp">
      <column length="29" name="date_created" not-null="true"/>
    </property>
    <property name="dateTerminated" type="timestamp">
      <column length="29" name="date_terminated"/>
    </property>
  </class>
</hibernate-mapping>


When I qualified the location of the sequence under my stocks schema, it worked again.

My observation is this..... Hibernate seems to be handling Postgres hibernate_sequence incorrectly. It seems to ignore the schema definition as defined in the ..hbm.xml file. Or is there a way to define which schema that Hibernate will look in for the sequence generator?

Any comments are welcomed and desired.

Stephen McConnell

"First appearances can be deceiving. But then so can second and third glances when you already have an agenda."
-- Lamar Stephens


Top
 Profile  
 
 Post subject: Re: GENERATING SEQUENCES and PostgreSQL Schemas
PostPosted: Sun Mar 01, 2009 4:30 pm 
Newbie

Joined: Sun Mar 01, 2009 4:17 pm
Posts: 1
You can define default db schema in hibernate configuration file (hibernate.cfg.xml):
Code:
<hibernate-configuration>
   <session-factory>
      ...
      <property name="hibernate.default_schema">myschema</property>
      ...
   </session-factory>
</hibernate-configuration>

persistence configuration file (persistence.xml):
Code:
<persistence>
   ...
   <persistence-unit>
      ...
      <properties>
         ...
         <property name="hibernate.default_schema" value="myschema" />
         ...
      </properties>
   </persistence-unit>
</persistence>

or in any other places where you are able to put hibernate properties.

a5phyx


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.