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

  • Home
  • SEARCH
  • 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 8383157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:05:41+00:00 2026-06-09T17:05:41+00:00

My Hibernate annotations work when my application is running on the server, but when

  • 0

My Hibernate annotations work when my application is running on the server, but when I try to test my Hibernate classes with JUnit I get the following error:

org.hibernate.MappingException: Unable to find column with logical name base_batch_id in table T_BASE_EXT
at org.hibernate.cfg.Configuration$MappingsImpl.getPhysicalColumnName(Configuration.java:3550)
at org.hibernate.cfg.IndexOrUniqueKeySecondPass.addConstraintToColumn(IndexOrUniqueKeySecondPass.java:87)
at org.hibernate.cfg.IndexOrUniqueKeySecondPass.doSecondPass(IndexOrUniqueKeySecondPass.java:77)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
at foo.BaseTest.setUp(BaseTest.java:31)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I believe this has something to do with the @Index annotation at BaseExt class. My annotated classess are working and can’t change them, but is there something that I can do to my Hibernate configuration in the JUnit test to get this working?

I’ve found a ticket that had a similar issue: https://hibernate.onjira.com/browse/ANN-207

Here is a JUnit test to replicate this error:

Abstract base class:

@MappedSuperclass
public abstract class Base implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_GEN", sequenceName = "SEQ", initialValue = 1)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_GEN")
    private Long id;

    public Long getId() {
        return id;
    }

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

Class that extends the abstract class:

And it also has a ManyToOne relationship to BaseBatch-class

@Entity
@Table(name = "T_BASE_EXT")
@org.hibernate.annotations.Table(appliesTo = "T_BASE_EXT", indexes = {
        @Index(name = "IDX_CDA_1", columnNames = {"BASE_BATCH_ID"})
})
public class BaseExt extends Base implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @ForeignKey(name = "CDA_BASE_BATCH_FK")
    private BaseBatch baseBatch;

    public BaseBatch getBaseBatch() {
        return baseBatch;
    }

    public void setBaseBatch(BaseBatch baseBatch) {
        this.baseBatch = baseBatch;
    }

}

BaseBatch:

@Entity
@Table(name = "T_BASE_BATCH")
public class BaseBatch extends Base implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

}

The JUnit test:

public class BaseTest extends TestCase {
    private SessionFactory sessionFactory = null;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        final String driverClass = "org.hsqldb.jdbcDriver";
        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Configuration cfg = new Configuration()
        .setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect")
        .setProperty("hibernate.connection.driver_class", driverClass)
        .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:basetest")
        .setProperty("hibernate.hbm2ddl.auto", "create");

        cfg.addAnnotatedClass(Base.class);
        cfg.addAnnotatedClass(BaseExt.class);
        cfg.addAnnotatedClass(BaseBatch.class);

        sessionFactory = cfg.buildSessionFactory();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        sessionFactory.close();
    }

    public void testBase() {
        sessionFactory.openSession();
        assertTrue(true);
    }
}

I’m using Hibernate Annotations 3.2.0.Final and Hibernate 3.6.9.Final

  • 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-09T17:05:42+00:00Added an answer on June 9, 2026 at 5:05 pm

    Add this annotation on

    @AttributeOverride(name="id", column=@Column(name="base_batch_id"))
    private BaseBatch baseBatch;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using hibernate annotations and when I do following everything works fine sessionFactory
I have an entity defined as follows @Entity(name = Report) @Table(name = REPORTS) @org.hibernate.annotations.Entity(dynamicInsert
I'm trying to combine Spring with Hibernate using Annotations and I'm getting the following
I'm using Spring and Hibernate with annotation-driven transactions. When running my application I've received
I have class class DateOptTimeType implements org.hibernate.usertype.UserType that works with two columns @org.hibernate.annotations.Type(type =
I'm trying to learn to work with Hibernate but probably i don't understand @ManyToOne
I'm working with Spring 3.1.2 and Hibernate 4.1.4.Final, but I don't work run my
I have an application using hibernate 3.1 and JPA annotations. It has a few
Is there any way I can use JPA or hibernate annotations to specify the
To keep it short and sweet: There is hibernate-commons-annotations 4.1.0-Final and hibernate-annotations 3.5.6-Final. I'm

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.