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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:32:56+00:00 2026-06-13T12:32:56+00:00

Got 3 tables I need to connect. Got my first project where I am

  • 0

Got 3 tables I need to connect.

Got my first project where I am making the database myself, while learning a new framework, which can be kinda confusing as I am not that well off when it come down to DBs.

I am using Spring 3.1.0.RELEASE and Hibernate 3.6.8.Final

I will name the most important attributes here, to give the general idea of what it is I am trying to achieve here.

Inventory (id, ItemName…)

Line_Items (WORKSHOP_ORDERS_Id, INVENTORY_Id, Quantity)

Workshop_Order (Id, WorkshopService, WorkshopNotes…)

This way I can hopefully have more than one item for each order, planning to hold one Line_Items for each different product in every order, linking it to the correct order by FKs.

I have tried different things with my annotations, my persistence.xml works, this is the only place in my code where there are any issues. I am 100% clueless on how to map this relation with annotations, so I am going to post my code here, even though it is no where near anything useful (but I may get some pointers).

import java.io.Serializable;

import javax.persistence.*;

@Entity
@Table(name = "LINE_ITEMS")
public class LineItems implements Serializable {

private static final long serialVersionUID = 2414994088922470197L;

public Long workshopOrderId;
public Long inventoryId;
public int quantity;

public Workshop workshop;
public Inventory inventory;

@OneToMany(mappedBy = "workshop",cascade = CascadeType.ALL)
@JoinColumn(name="WORKSHOP_ORDERS_Id", insertable = false, updatable = false, nullable = false)
public Workshop getWorkshop() {
    return workshop;
}

@OneToMany(mappedBy = "inventory", cascade = CascadeType.ALL)
@JoinColumn(name="INVENTORY_Id", insertable = false, updatable = false, nullable = false)
public Inventory getInventory() {
    return inventory;
}

public void setWorkshop(Workshop workshop) {
    this.workshop = workshop;
}

public void setInventory(Inventory inventory) {
    this.inventory = inventory;
}

@Id
@Column(name = "WORKSHOP_ORDERS_Id")
public Long getWorkshopOrderId() {
    return workshopOrderId;
}

@Id
@Column(name = "INVENTORY_Id")
public Long getInventoryId() {
    return inventoryId;
}

@Column(name = "Quantity")
public int getQuantity() {
    return quantity;
}   

public void setWorkshopOrderId(Long workshopOrderId) {
    this.workshopOrderId = workshopOrderId;
}

public void setInventoryId(Long inventoryId) {
    this.inventoryId = inventoryId;
}

public void setQuantity(int quantity) {
    this.quantity = quantity;
}

}

I have heard some talk about a bug in Hibernate, but not sure if this relates to my issue.

Basically what I need is not necessary the complete solution to the problem, but some idea of what I am doing and what I should do to correct it. I would love some assistance in both smart database design (regarding the tables I have shown, and the correct way to do it in Hibernate).

Any advice or help will be appreciated.

  • 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-13T12:32:58+00:00Added an answer on June 13, 2026 at 12:32 pm

    As per the description of tables you gave below are the relationships.

    Assumtpions:
    - Many line_item is connected to one WorkshopOrder
    - Many Line_items can be connected to same inventory
    
    Line_Items (WORKSHOP_ORDERS_Id, INVENTORY_Id, Quantity)
                       |               |
                       |            ManyToOne
                     ManyToOne          |
                       |             Inventory (id, ItemName...)
                       |
                      Workshop_Order (Id, WorkshopService, WorkshopNotes...)
    

    Currently in you entity you used OneToMany but one to many means one item can have many orders so order will become collection. SO that doesn’t seem right.

    EDIT: EDITED RELATIONSHIP BETWEEN ITEM & WORKSHOP TO MANYTOONE INSTEAD OF ONETOONE AS PER COMMENT.

    LineItems.java
    
      @ManyToOne
      WorkshopOrder w;
    
      @ManyToOne
      Inventory i;
    
    WorkshopOrder.java
    
      @OneToMany
       List<LineItems> items;
    
    Inventory.java
    
      @OneTOMany
       List<LineItems> items;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two tables from which I need to extract information, but the data
I've got an upcoming project wherein I will need to connect our website (
I have been making a database and learning along the way. I recently got
I got two tables in my database: user and call. User exists of 3
I got two tables, one of which is a helper of the other. The
I've got 2 tables. The first table is full of entries. The second table
i've got to connect 2 php pages on 2 different servers, in the first
I'm transferring my access logs into a database. I've got two tables: urlRequests id
I need to connect to a MySQL database via C# express 2008. I think
So I've got a large database that I can't hold in memory at once.

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.