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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:29:39+00:00 2026-05-23T22:29:39+00:00

I am trying to do do JPA/Hibernate mappings to map two tables, but am

  • 0

I am trying to do do JPA/Hibernate mappings to map two tables, but am getting this error. any help would be greatly appreciated!!

Restaurants.java

@Entity
@Table(name="RESTAURANTS")
public class Restaurants{

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

    @OneToMany(mappedBy="restaurant")
    private LinkedList<Menus> menus = new LinkedList<Menus>();


    /* constructors **/
    public Restaurants(){
        this.dateJoined = new Date();
    };

    /* getters and setters **/

    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}

    public LinkedList<Menus> getMenus() {return menus;} 
    public void setMenus(LinkedList<Menus> menus) {this.menus = menus;}

}

Menus.java

@Entity
@Table(name = "MENUS")

public class Menus {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private Long restaurantID;

    @OneToMany
    @JoinColumn(name="restaurant")
    private Restaurants restaurant;

    /* constructors */

    public Menus(){}

    /* getters and setters */

    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    @Column(nullable = false)
    public Long getId() {return id;}    
    public void setId(Long id) {this.id = id;}  

    public Long getRestaurantID() {return restaurantID;}    
    public void setRestaurantID(Long restaurantID) {this.restaurantID = restaurantID;}  

    public void setRestaurant(Restaurants restaurant) {this.restaurant = restaurant;}
    public Restaurants getRestaurant() {return restaurant;}
}

With this error

Exception in thread “main” org.hibernate.MappingException: Could not
determine type for: bb.entities.Restaurants, at table: MENUS, for
columns: [org.hibernate.mapping.Column(restaurant)] at
org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306) at
org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290) at
org.hibernate.mapping.Property.isValid(Property.java:217) at
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464)
at org.hibernate.mapping.RootClass.validate(RootClass.java:235) at
org.hibernate.cfg.Configuration.validate(Configuration.java:1362) at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865)
at bb.TestMain.setUp(TestMain.java:26) at
bb.TestMain.main(TestMain.java:59)

Thanks.

  • 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-23T22:29:41+00:00Added an answer on May 23, 2026 at 10:29 pm

    It appears to be a misconception in the use of the @OneToMany annotation. The @OneToMany annotation is used to represent the 1-side in a 1:M relationship, and the inverse @ManyToOne relationship is used to represent the M-side. Therefore, a @OneToMany annotation should be defined on a collection-type in an entity and not on a normal reference type.

    You should therefore:

    • use a @OneToOne association if that is the nature of the relationship between the entities.
    • or, decide which entity represents the 1-side in the 1:M relationship. Going by the use of the LinkedList class in Restaurants, I would consider the Restaurants class to be the 1-side, and use the @OneToMany annotation in the Restaurants class, while using the inverse @ManyToOne relationship in the Menus class. The refined code would be:

    Restaurants.java

    ...
    @OneToMany(mappedBy="restaurant")
    private List<Menus> menus = new LinkedList<Menus>();
    

    Menus.java

    @ManyToOne
    @JoinColumn(name="restaurant")
    private Restaurants restaurant;
    

    Note the change in the declaration of the menus member variable from LinkedList<Menus> to List<Menus>. Apparently, in this case, it is wiser to declare any collection with the interface-type of the collection, instead of the concrete collection class. The rationale is that the underlying JPA provider will use it’s own concrete collection types at runtime, for the purpose of proxying the collection values. Hibernate for instance, will use a PeristentList at runtime, to represent the List in a managed entity, and not a LinkedList as created by the entity. If you use the concrete type, Hibernate might fail in mapping the column, or might fail in retrieving the associated records from the database; I’m not sure about the specifics of the runtime behavior, except that I know of the eventual failure.

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

Sidebar

Related Questions

I'm trying to add JPA support for my app however, I'm getting this error:
I am trying to configure Spring3 + JPA using Hibernate, but I am getting
I'm trying to set up the following tables using JPA/Hibernate: User: userid - PK
I am trying to map a JPA (using Hibernate) one-to-one relationship with a inheritance
I am trying my way around JPA but I cant get this to work
I'm trying to setup Spring using Hibernate and JPA, but when trying to persist
I'm trying to set up a Spring JPA Hibernate simple example WAR for deployment
I'm using Hibernate and JPA for a small project. Somehow when trying to obtain
I am trying to add Eclipse Dali JPA integration and to specify Hibernate as
I'm using Spring with Hibernate as a JPA provider and are trying to get

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.