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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:43:45+00:00 2026-05-30T04:43:45+00:00

I have an employer table with schema containing userprofileId The employer table as stated

  • 0

I have an employer table with schema containing userprofileId

The employer table as stated below is containing userprofileid which is primary key of user table

id                 int(11)      (not NULL)         PRI        
userprofileid      int(11)      (not nUll)                          
organization_name  varchar(50)  (not nUll)  

Now my requirement was create a JPA class for this employer.

Now we have Employer.java, with below entry.

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToOne(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(name="userProfileId", referencedColumnName="id" )
    @Column( insertable=false ,updatable =false)
    private UserProfile userProfile;

    @Column(name = "organization_name")
    private String organizationName;

Now hurdle is.
Our UserProfile is object is created in different method. Now i dont want to again add same value to userprofile table and so i made insertable = false and updatable = false in employer.java so that the field does not get updated;

No if i set the value of userprofile in employer object

it says

org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.hcentive.core.user.UserProfile; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.hcentive.core.user.UserProfile

but if i dont set the user profile it gives below error.

Caused by: java.sql.SQLException: Field 'userprofileid' doesn't have a default value

Note for persisting I am using :

getJpaTemplate().persist(t);
  • 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-30T04:43:46+00:00Added an answer on May 30, 2026 at 4:43 am

    Your Employer refers to an already existing user profile. If it already exists, it is in the database. If it is in the database, you must not create a new instance, but get it from the database. To get something from the database, you use the EntityManager.find() or EntityManager.getReference() method (the second one doesn’t even do any select statement).

    So, remove the insertable and updatable flags from your annotation (the association is insertable), and use code similar to the following one:

    UserProfile up = em.getReference(UserProfile.class, userProfileId);
    employer.setUserProfile(up);
    em.persist(employer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has (for example) 4 columns. pk_table_id INT NOT NULL
I have tables which looks like below. Employee table Date Employee ID Employer ID
I have a legacy SQL schema which looks something like this: CREATE TABLE `User`
Suppose I have employee and department table, employee has foreign key departmentID that is
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
I have a query like this: var q = db.GetTable<Person>().Where(x => x.Employer.CEO != null);
Consider the following scenario. I have a table (a stupid_table ) in a schema
I have an employee table which contains a manager ID as a column. If
I have the following table schema: RecordId EmpID AbsCode DateFrom DateTo --------------------------------------------------------------- 666542 1511
I have table 'stf_table' under the schema 'staff' with username 'staff'. I have table

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.