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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:28:24+00:00 2026-05-26T16:28:24+00:00

I got these 2 entities: @javax.persistence.Entity public class Book { @javax.persistence.EmbeddedId private BookPK id;

  • 0

I got these 2 entities:

@javax.persistence.Entity
public class Book {
    @javax.persistence.EmbeddedId
    private BookPK id;

    private String title;

    @javax.persistence.ManyToOne(fetch = javax.persistence.FetchType.LAZY)
    @javax.persistence.JoinColumns({ 
            @javax.persistence.JoinColumn(name = "LNGCOD", referencedColumnName = "LNGCOD"),
            @javax.persistence.JoinColumn(name = "LIBCOD", referencedColumnName = "LIBCOD") })
    private Language language;
}

@javax.persistence.Entity
public class Language {
    @javax.persistence.EmbeddedId
    private LanguagePK id;

    private String name;
}

with composed PK’s:

@Embeddable
public class BookPK implements Serializable {
    private Integer bookcod;
    private Integer libcod;
}

@Embeddable
public class LanguagePK implements Serializable {
    private Integer lngcod;
    private Integer libcod;
}

If I try to create a new Book and persist it, I get an exception telling me libcod is found twice in the insert statement (“Column ‘libcod’ specified twice”). But I can’t use “insertable = false” when defining the JoinColumn (“Mixing insertable and non insertable columns in a property is not allowed”).

Is there any way to define these objects + relationship so the columns are managed automatically by Hibernate ?

  • 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-05-26T16:28:25+00:00Added an answer on May 26, 2026 at 4:28 pm

    Hibernate and JPA automatically make persistent all the modifications made to persistent entities while they are attached to the session. That’s the whole point of an ORM: you load a persistent object, modify it, and the new state is automatically persisted at the commit of the transaction, without any need to call persist, merge, save or any other method.

    Note that calling persist on a persistent entities (except for its cascading side-effects) makes no sense. persist is to make a transient entity (i.e. a new one, not in the database yet, with no generated ID) persistent.

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

Sidebar

Related Questions

I have got these POCO classes: public class Task { public int TaskId {
Got these 2 queries: select d1.field_id_41 program_code, d1.field_id_48 program_group_code, t1.title program_lookup, t2.title group_title, t1.url_title
I've got these models class PlayersToTeam < ActiveRecord::Base belongs_to :player belongs_to :team accepts_nested_attributes_for :player
I've got task to fast find object by its string property. Object: class DicDomain
I am using Entity framework 5 and using repository pattern. Say I got these
I'm having an issue updating an entity with multiple related entities. I've got a
I've got the following entities on my EDMX :- These two entites were generated
I've got some entities which have decimal properties on them. These entities' properties are
So I've got some data. There are entities. Entities have an arbitrary number of
I've got these facebook permissions set in my app: NSArray *permissions = [[NSArray alloc]

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.