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 9169517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:24+00:00 2026-06-17T15:53:24+00:00

I am running in-container tests with arquillian. I am prepopulating the database by adding

  • 0

I am running in-container tests with arquillian. I am prepopulating the database by adding an import.sql to the deployment. During the test I would like to create some more entities.

Unfortunately, this fails with a PersistenceException:

javax.persistence.PersistenceException:
org.hibernate.exception.ConstraintViolationException: Unique index or
primary key violation: “PRIMARY_KEY_BE ON
PUBLIC.KVS_MIPO_DOWNLOAD(ID)”

If I do not prepopulate the DB, or do not persist new entities, everything runs smoothly.

The id is the only unique field, so I strongly suspect that it must be the id generation using a sequence.

@Entity
@Table(name = "KVS_MIPO_DOWNLOAD")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class DownloadResource implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Integer id;

This entity is the superclass of another concrete entity, which does not add any unique attributes.

What can be done to be able to accomodate both possibilitiees – inserting manually and using a generated id?

Thank you

I am working with JPA 2 over Hibernate 4.0.1 in JBoss 7.1.1. The database is Sybase ASE 15.

EDIT: one workaround I have found so far is to set the Ids of the manually added entities high enough to avoid collisions. But this is not good enough for production – too many employees have write access to the db and may be tempted to add stuff manually. I would prefer the application to be robust enough not to die and explode in this case.

  • 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-17T15:53:25+00:00Added an answer on June 17, 2026 at 3:53 pm

    Use negative values for your manual ids. Hibernate shouldn’t generate negative ones.

    Optionally, use your own id generator that skips a particular range (or skips say numbers divisible by 7; some such scheme).

    Sample ID generator:

    import org.hibernate.HibernateException;
    import org.hibernate.engine.SessionImplementor;
    import org.hibernate.id.IdentifierGenerator;
    
    public class MyGenerator implements IdentifierGenerator {
    
        public Serializable generate(SessionImplementor session, Object object)
                throws HibernateException {
            return 1; // TODO: Your scheme to create an Integer;
        }
    }
    

    To use this annotate as follows:

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "myid")
    @GenericGenerator(name = "myid", strategy = "com.x.y.z.MyDGenerator")
    public int getId() {
        return _id;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running as a test application in Eclipse: ` //import all needed functionality import javax.swing.*;
Since I'm running Java with Tomcat6 as servlet container I found it appropriate to
I'm running into an odd problem with MEF's composition container and directory catalog where
I have a legacy Java servlet that is currently running in a Tomcat container.
I have a application that is deployed on tomcat container. I'm running the jmeter
I have the following code to test memory deallocation using a std::list container: #include
When running a unit test, the configuration file is not read properly. However, when
I have a structure of simple container classes like so (in pseudo ruby): class
I am seeing some dead-instance weirdness running parallelized nested-loop web stress tests using Selenium
I have trouble running Guice 3 within an OSGi container. Following is a simple

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.