Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:28:08+00:00 2026-06-11T20:28:08+00:00

I am using DB2 database and hibernate framework. There are two tables such as

  • 0

I am using DB2 database and hibernate framework. There are two tables such as Word and Litter and their relationship is one to many.

  1. Schema A:

    Table Word: ID,
    IDLIT -> references to ID of Litter table
    Name
    
  2. Schema B:

    Table Litter ID,
    Short_Name,
    Long_Name.
    

Both tables are located in two different schemas but in one database. I have an POJO and XML mapping files to map the tables. Now how can I save the objects into database while handling the many to one relationship(Litter – Word)? Is the any suggestion? If yes please provide me with detailed instructions, thanks in advance!

Updated question

Also I have changed because my mapping xml files different for each POJO class. Here is the code for running:

 Session session = HibernateUtility.getSessionFactory().openSession();
   session.beginTransaction();

   Word word = new Word();
   Word word1 =new Word();

   Litter litter = new Litter();
   litter.setFullname("bla bla");
   word.setLitter(litter);    
   word1.setLitter(litter); //Here I have to handle one to many relationship

   Set Words =new  HashSet();
   Words.add(word);
   Words.add(word1);
   litter.setWords(words);
   session.save(litter);
   session.save(word);
   session.save(word1);
  session.getTransaction().commit();
  session.close();

But this code giving an exception: JDBCExceptionReporter logExceptions
Is the approach which I am using is correct?

Stack trace------------------
INFO: schema update complete
Hibernate: select max(ID) from LITTER
сен 25, 2012 7:33:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: -204, SQLState: 42704
сен 25, 2012 7:33:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=BIMASH.LITTER, DRIVER=3.64.104
сен 25, 2012 7:33:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: -204, SQLState: 42704
сен 25, 2012 7:33:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=BIMASH.LITTER, DRIVER=3.64.104
сен 25, 2012 7:33:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: -727, SQLState: 56098
сен 25, 2012 7:33:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-204;42704;BIMASH.LITTER, DRIVER=3.64.104
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107)
    at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
    at Main.main(Main.java:73)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:28:09+00:00Added an answer on June 11, 2026 at 8:28 pm

    You can define the schema a mapped class belongs to with the schema attribute of the <class> element in the mapping file. Notice this will override the setting in the general <hibernate-mapping>‘s schema attribute.

    <!-- A is set to be the default schema -->
    <hibernate-mapping schema="A">
        <class name="mypackage.Word" table="WORD" >
        ....
        </class>
    
        <!-- Overriding the schema definition for this class -->
        <class name="mypackage.Litter" table="LITTER" schema="B">
        ....
        </class>
    </hibernate-mapping>
    

    The following Hibernate reference chapter might be worth a read: Chapter 5. Basic O/R Mapping, specially the sections about the <hibernate-mapping> and <class> elements.

    UPDATE

    Seeing the stack trace, it seems that a <generator class="increment"> is being used in the class. If it’s the case (it seems so by the select max(ID) from LITTER query), you’ll also have to specify the schema in the <generator> so that the issued query transforms into select max(ID) from B.LITTER. You can achieve that with a <param> named schema in the <generator>:

    <generator class="increment">
        <param name="schema">B</param>
    </generator>
    

    For more details see this almost duplicate question: Hibernate: ID generator using increment and Oracle Schema

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My DB2 database is using UTF-8 encoding. The source table has one colum with
I am using db2 and I want to find tables, having a column named
I would like to connect to a DB2 database, specifically an iSeries version, using
i'm trying to configure a datasource of an db2 database in tomcat (using eclipse
I'm using NHibernate to connect to an ERP database on our DB2 server. We
I am currently using Toad for DB2 to work on my DB2 database. I
I create a custom schema in my DB2 database using the following command: db2
I have a .Net application which interacts with a DB2 database (Entity Framework, not
Hey I'm trying to connect to a DB2 database, by using Servlets (Using NetBeans
I'm running an SQL query against a mainframe DB2 database using the OdbcDataReader class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.