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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:09:38+00:00 2026-05-24T20:09:38+00:00

Anyone have any ideas why hibernate v3.6.7 has problems with the seemingly simple class

  • 0

Anyone have any ideas why hibernate v3.6.7 has problems with the seemingly simple class hierarchy below?

@Entity
public class X implements Serializable {
    @Id
    String id;

    X() {

    }

    public X(String id) {
        this.id = id;
    }
}

interface PK {
    Object getPK();
}

@Entity
public class Y  implements Serializable, PK {
    @Id
    @OneToOne
    @JoinColumn(name ="id")
    X x;

    protected Y() {

    }

    public Y(X x) {
        this.x = x;
    }

    @Override
    public Object getPK() {
        return x.id;
    }
}

private static final EntityManager em;
private final CriteriaBuilder cb = em.getCriteriaBuilder();
private final CriteriaQuery<Y> query = cb.createQuery(Y.class);
private final Root<Y> entity = query.from(Y.class);

static {
    Map<String, Object> properties = new HashMap<String, Object>();
        // initialise properties appropriately
    EntityManagerFactory emf =
        Persistence.createEntityManagerFactory("myPersistenceUnit", properties);
    em = emf.createEntityManager();

}

@Test
public void simpleTest() {
    X x1 = new X("X1");
    X x2 = new X("X1");
    List<Y> yy = new ArrayList<Y>();

    Y yX1 = new Y(x1);
    yy.add(yX1);

    Y yX2 = new Y(x2);
    yy.add(yX2);

    saveItems(yy);

    String name = "x";
    Path<Object> path = entity.get(name);
    Predicate restriction = cb.conjunction();
    restriction = cb.and(restriction, cb.and(new Predicate[]{cb.equal(path, x1)}));

    TypedQuery<Y> tq = em.createQuery(this.query);
    Y result = null;

    try {
        result = tq.getSingleResult();
    } catch (NoResultException e) {
    }

    assertNotNull(result);
}

attempting to execute this test throws the following exception:

java.lang.IllegalArgumentException: Unable to resolve attribute [x] against path
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:118)
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:223)
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:194)
    at com.example.entity.impl.MyPersistenceTest.simpleTest(MyPersistenceTest.java:212)
  • 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-24T20:09:41+00:00Added an answer on May 24, 2026 at 8:09 pm

    I have the feeling that the mapping is a bit wrong.

    First, X is missing @Embeddable and Y.x should be mapped as @EmbeddedId, not as @Id.

    Extending that Bozho said, if you want to use an class as both ID and Entity, you need to create a super class and one subclass of each usage (PK and entity) with the mapping annotations.

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

Sidebar

Related Questions

Anyone have any ideas what I can do? Please reserve commenting about using 1.1
Anyone have any ideas on a good way to model the following scenario in
Does anyone have any ideas on how to read the MSDTC configuration on the
Does anyone have any ideas how to get the Accordion control in the ASP.Net
Anyone have any idea about CASlotProxy Class in Cocoa (iOS SDK)? I found it
Anyone have any ideas on how to test for something specific for IE6 (and
Does anyone have any ideas how to shift up the remaining fields after suppressing?
I'm a little stumped on this one. Anyone have any ideas? I'll try to
Does anyone have any ideas why a test would pass when run with ant,
I am using Hibernate to map with MySQL I have an entity class in

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.