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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:20:50+00:00 2026-05-26T06:20:50+00:00

I have a Formula defined as: @Entity @Table(name = MyEntity) @org.hibernate.annotations.Table(appliesTo = MyEntity) public

  • 0

I have a Formula defined as:

@Entity
@Table(name = "MyEntity")
@org.hibernate.annotations.Table(appliesTo = "MyEntity")
public class MyEntity
{
    @Enumerated(value = javax.persistence.EnumType.STRING)
    @Transient
    @Formula(value = "select e.state from OTHER_ENTITY e")
    private State state;

    public State getState()
    {
        return this.state;
    }
//setter and another properties
}

But it is ignoring it.

Here is my Persistence Unit:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="myPersistence" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <mapping-file>META-INF/orm.xml</mapping-file>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.url" value="jdbc:mysql://url:3306/db" />
        <property name="hibernate.connection.username" value="root" />
        <property name="hibernate.connection.password" value="root" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
    </properties>
</persistence-unit>

The sql are generated without the Formula.

If I remove the @Transient the JPA tries to load the state column and then fails.

I want to calculate the state based on the state of another entity. That’s why the I think a Formula works.

Thank you!

Udo.

  • 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-26T06:20:50+00:00Added an answer on May 26, 2026 at 6:20 am

    You’re trying to map the state twice : once by adding annotations to the field, and once by adding annotations to the getter. Put all the annotations at the same place (and at the same place as the @Id annotation).

    But this is really confusing. Your state is transient (meaning it’s not mapped at all, and should not be read from the database), but it’s also enumerated (why would Hibernate use this annotation since it’s supposed to be transient), and a formula.

    Finally, a formula is some piece of SQL that’s added in every SQL that is used to load your entity. So it should not contain a select clause, or a from clause, but just a formula using some of the columns of the table itself. For example, suppose you have a table with a column salary and a column bonus, you could have a formula for a field totalIncome which would be ‘bonus + salary’. But id doesn’t go much further than that.

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

Sidebar

Related Questions

I have a class which I want to add a property with using formula
I have this formula in a cell: =GetData(Channel_01,Chicago) Which executes this code: Public Function
We would like to have user defined formulas in our c++ program. e.g. The
is there a way in Excel to have a formula that does something like
In excel 2007, I have a formula in a cell like the following: =COUNTIFS('2008-10-31'!$C:$C;>=&'$A7)
I have the following formula float mean = (r+b+g)/3/255.0f; I want to speed it
Does anyone have the secret formula to resizing transparent images (mainly GIFs) without ANY
I have been trying to use a formula that is used to work out
I have a set of expressions representing some formula with some parameters inside. Like:
I have a calculated field in a list with this formula: =CID & -

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.