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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:14:56+00:00 2026-05-16T22:14:56+00:00

Category EJB package session; import com.Entity.Category; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; Item EJB

  • 0

Category EJB

package session;

import com.Entity.Category;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

Item EJB

package session;

import com.Entity.Item;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class saveItemBean implements saveItemRemote {

    @PersistenceContext
    private EntityManager em;

    public void saveItem(Item itm) {
        em.persist(itm);
    }

    public void persist(Object object) {
        em.persist(object);
    }
}

Servlet for save Item

package src;

import com.Entity.Item;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import session.CategoryFacadeRemote;
import session.saveItemRemote;

public class saveItemAndIemCategory extends HttpServlet {
    @EJB
    private saveItemRemote saveItemBean;

    @EJB
    private CategoryFacadeRemote categoryFacadeBean;

    processRequest(HttpServletRequest request, HttpServletResponse response) {
        try {
            Item itm = new Item();
            itm.setName("HelloNew");
            saveItemBean.saveItem(itm);
        } catch (Exception e) {
            e.printStackTrace();      
        } finally {
            out.close();
        }
    } 

}

Item Entity Bean

package com.Entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "item")
@NamedQueries({@NamedQuery(name = "Item.findAll", query = "SELECT i FROM Item i"), @NamedQuery(name = "Item.findByItemId", query = "SELECT i FROM Item i WHERE i.itemId = :itemId"), @NamedQuery(name = "Item.findByName", query = "SELECT i FROM Item i WHERE i.name = :name")})
public class Item implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "item_id")
    private Integer itemId;

    @Basic(optional = false)
    @Column(name = "name")
    private String name;

    @ManyToMany
    @JoinTable(name = "item_cat", 
        joinColumns = {@JoinColumn(name = "item_id", referencedColumnName = "item_id")}, 
        inverseJoinColumns = {@JoinColumn(name = "cat_id", referencedColumnName = "cat_id")})
    private List<Category> categoryCollection;

    public Item() {
    }

    public Item(Integer itemId) {
        this.itemId = itemId;
    }

    public Item(Integer itemId, String name) {
        this.itemId = itemId;
        this.name = name;
    }

    public Integer getItemId() {
        return itemId;
    }

    public void setItemId(Integer itemId) {
        this.itemId = itemId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Category> getCategoryCollection() {
        return categoryCollection;
    }

    public void setCategoryCollection(List<Category> categoryCollection) {
        this.categoryCollection = categoryCollection;
    }

}

I am trying to persist data using these coding but only Category and Item tables are getting field (Category coding are missing here those are fine) my assosiative table item_cat is not getting saving data.

  • 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-16T22:14:56+00:00Added an answer on May 16, 2026 at 10:14 pm

    If you have an intermediate join table, you need to use the @JoinTable annotation:

    @JoinTable(name="item_cat", joinColumns={ @JoinColumn(name="item_id") }, inverseJoinColumns={ @JoinColumn(name="category_id") })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the path: Format: http://mydomain.com/ {category}/{subcategory}/{pageNumber}/{pageSize} Example: http://mydomain.com/books/thriller/3/25 In the querystring: Format: http://mydomain.com/ {category}/{subcategory}?
I have a custom category (disciplines) in my method plugin which I want to
I have a custom performance counter category. Visual Studio Server Explorer refuses to delete
Consider two tables transaction and category each having their own ID and information. A
table data of 2 columns category and subcategory i want to get a collection
i have a table called category in which i have main category ids and
I have a products table that contains a FK for a category, the Categories
I am using wordpress and use custom permalink structure: /%category%/%postname%/ My problem is that
I have a table story_category in my database with corrupt entries. The next query
I have a numerical field called category_id in my table. I want to do

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.