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

  • Home
  • SEARCH
  • 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 8982277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:32:26+00:00 2026-06-15T20:32:26+00:00

I tried to use ORM with Hibernate annotation in Spring but when i would

  • 0

I tried to use ORM with Hibernate annotation in Spring but when i would like to make jointures it fails.

I have two tables (according to java class) :

Product (PK productId, FK productGroup)
ProductGroup (PK productGroupTri)

Product.java

@Entity
@Table(name="product")
public class Product implements Serializable{

@Id
@Column(name="product_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int productId;

@Column(name="product_name")
private String productName;

@OneToOne
@PrimaryKeyJoinColumn
private ProductGroup productGroup;

public void setProductId(int productId) {
    this.productId = productId;
} 

public int getProductId() {
    return this.productId;
} 

public void setProductName(String productName) {
    this.productName = productName;
} 

public String getproductName() {
    return this.productName;
} 

public void setProductGroup(ProductGroup productGroup) {
    this.productGroup = productGroup;
} 

public ProductGroup getProductGroup() {
    return this.productGroup;
}
}

ProductGroup.java

@Entity
@Table(name="product_grp")
public class ProductGroup {

@Id
@Column(name="grp_tri")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String productGroupTri;

@Column(name="grp_div")
private String productGroupDiv;

@OneToOne(mappedBy="productGroup", cascade=CascadeType.ALL)
private Product product;

public void setProductGroupTri(String productGroupTri) {
    this.productGroupTri = productGroupTri;
} 

public String getProductGroupTri() {
    return this.productGroupTri;
} 

public void setProductGroupDiv(String productGroupDiv) {
    this.productGroupDiv = productGroupDiv;
} 

public String getProductGroupDiv() {
    return this.productGroupDiv;
} 

public void setProduct(Product product) {
    this.product = product;
}

public Product getProduct() {
    return this.product;
}
}

And the HQL request that fails :

String hql = "from Product as p where p.productId = :id";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    query.setInteger("id", productId);

    return (Product) query.uniqueResult();

I’ve got the following message :

org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.String, got class java.lang.Integer

I would like to access to the group name of a product and I understand it’s because of the type of the Primary and Foreign Key but i didn’t find any issue although i’ve done search on forums.

Thanks for your help

  • 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-06-15T20:32:27+00:00Added an answer on June 15, 2026 at 8:32 pm

    @carbontax, i did this HQL :

    String hql = "select p from Product as p join p.productGroup as g where p.productId = :id";
    

    Then, i find an issue to correct this error. In fact, i had this code to access to the column in my JSP :

    <td class="GlobalInfoTitle">Group</td><td><c:out value="${model.product.grp_tri}"/></td>
    

    And i correct this with :

    <td class="GlobalInfoTitle">Groupe</td><td><c:out value="${model.product.productGroup.grp_tri}"/></td>
    

    I had also modify the cardinality in Product.java to ManyToOne And in ProductGroup.java to OneToMany.

    The major problem is that i accessed to the object Product to get my property instead the object ProductGroup.

    If someone got the same problem as me he can ask me help cause the issue is easy finally …

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

Sidebar

Related Questions

I tried to use Hibernate Envers to log the entity histroy. but failed. My
I tried to use BoneCP with my JSF-Spring-Hibernate combination, following BoneCP configurations on their
I'm building a web app and would like to use an ORM to map
I tried to use an image file in my HTML template. But when I
I tried to use object expression to extend the IDelegateEvent, but in fsi there
Specifically, I'm trying to use a string to arbitrairly filter the ORM. I've tried
I'm trying to use JPA 2.0 in Spring 3.0 ORM. The JPA vendor is
I am trying to translate a sql query in django's ORM. Tried to use
I have already tried a lot of ORM mappers and there seems to be
I tried to setup infinispan as 2nd level cache for hibernate in spring+tomcat based

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.