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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:52:43+00:00 2026-05-27T20:52:43+00:00

After much searching and trials, I am stuck… I have two classes, one is

  • 0

After much searching and trials, I am stuck… I have two classes, one is ExpectedSecurityReturn and the other is ForecastReturnType. ForecastReturnType is a member of ExpectedSecurityReturn but should not be inserted when persisting data. I keep getting an “insufficient privileges” but I know that the user does have the delete/insert privileges to the table expected_security_return since I tested with JDBC and JPA delete works fine. Therefore, I think that it has to do with my classes.

@Table(name = "EXPECTED_SECURITY_RETURNS")
@Entity
@IdClass(ExpectedSecurityReturn.ExpectedSecurityReturnPK.class)
public class ExpectedSecurityReturn {

@Id
@Column(name = "REP_SEC_ID")
private Integer repSecId;

@Id
@Column(name = "AS_OF_DATE")
private Date date;

@Id
@ManyToOne(optional = false)
@JoinColumn(name = "RETURN_TYPE_ID", referencedColumnName = "RETURN_TYPE_ID", insertable=false)
private ForecastReturnType returnType;

@Column(name="CURR_TOUSD_RET")  // local currency to usd 
private Double currencyToUsdReturn;
}

The primary key class, which includes ForecastReturnType:

    // ------------------------------
// PK
// ------------------------------
public static class ExpectedSecurityReturnPK implements Serializable {

    private static final long serialVersionUID = 1325372032981567439L;

    public ExpectedSecurityReturnPK() {
    }

    public ExpectedSecurityReturnPK(final Integer repSecId,
            final Date asOfDate, ForecastReturnType returnType) {
        if (repSecId == null)
            throw new IllegalArgumentException("null rep sec id");
        if (asOfDate == null)
            throw new IllegalArgumentException("null asOfDate");
        if (returnType == null)
            throw new IllegalArgumentException("null returnType");

        this.repSecId = repSecId;
        this.date = new Date(asOfDate.getTime());
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        final ExpectedSecurityReturnPK that = (ExpectedSecurityReturnPK) o;

        if (repSecId != that.repSecId)
            return false;
        if (!date.equals(that.date))
            return false;
        if (!returnType.equals(that.returnType))
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = repSecId;
        result = 31 * result + date.hashCode();
        result = 31 * result + returnType.getForecastTypeId();
        return result;
    }

    private int repSecId;
    private Date date;
    private ForecastReturnType returnType;
}

and ForecastReturnType:

@Table(name="EXPECTED_SEC_RET_TYPE_DECODE")
@Entity
public class ForecastReturnType {

@Id
@Column(name="RETURN_TYPE_ID")
private int forecastTypeId;

@Column(name="SHORT_NAME")
private String shortName;

@Column(name="LONG_NAME")
private String longName;

@OneToMany(fetch=FetchType.LAZY, mappedBy="returnType")
Collection<ExpectedSecurityReturn> expectedSecurityReturns;
}

Could anyone help me figure out what I am doing wrong? I tried many things without success… I think that the culprit is ExpectedSecurityReturn.returnType since I know that the user does not have privileges.

Basically, I need to insert/persist ExpectedSecurityReturn instances.

  • 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-27T20:52:43+00:00Added an answer on May 27, 2026 at 8:52 pm

    Well, there’s a couple of things.

    I would heavily not recommend even trying to do this. You can waste away your life figuring out JPA annotations and weird issues like this that never quite seem to work right. You’ll also find that different JPA providers will behave slightly differently when it comes to more complex structures like this, and it goes doubly for inheritance.

    You’re really much better off creating a unique key on EXPECTED_SECURITY_RETURNS, and just living with it, it will make your Java life much much easier.

    If you have to do something like this, I’m not surprised that JPA is balking at having a primary key component be another entity object. Whilst this in of course quite possible in the RDBMS, it’s seemingly little things like this that will trip up JPA.

    I would also check the query logs that your JPA impl will put out (it’s configurable fairly easily in the persistence definition for most JPA providers, certainly Ecpliselink and Hibernate). I’d be willing to bet it’s trying to run an update on EXPECTED_SEC_RET_TYPE_DECODE, and if not, it might be trying to obtain a lock (table, row or other depending on your DBMS). If the user doesn’t have permission to either execute a lock or an update on that table, depending on the exact implementation, the query could fail with a permissions problem.

    It is reasonable for JPA to want to hold a lock on that table because there is a chance that during the transaction, the entry that is being referenced in EXPECTED_SEC_RET_TYPE_DECODE may get changed, so it must ensure that it doesn’t whilst updating/inserting on the other table. Last I checked, there is no way to tell JPA that this table is essentially static. If you’re using Hibernate, you might try the @ReadOnly annotation, but in the past, not much I’ve tried can get around things like this.

    If you do find a better solution, feel free to post it so that the rest of us can learn!!

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

Sidebar

Related Questions

After much searching the answer seems to be no, but I thought I'd ask
I know it have been discussed already at some point. But after searching there
After Much searching I have decided to ask my first stack overflow question: View
After much searching, it looks like I have to assign RegisterComponentsProc and RegisterPropertyEditorProc ,
I know about $(Delphi) and $EDNAME but after much seaching I cant find a
After much googling I have been wondering what the benefits/differences are between mysql and
After much fiddling, I've managed to install the right ODBC driver and have successfully
After searching stackoverflow.com I found several questions asking how to remove duplicates, but none
After much searching, I found the download for the eclipse version of jalopy .
It appears after much searching that there seems to be a common problem when

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.