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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:05:09+00:00 2026-06-04T02:05:09+00:00

I am using JPA to persist data. I am new to whole of Java-ee

  • 0

I am using JPA to persist data. I am new to whole of Java-ee programming so please let me if I am doing it wrong way. I have 2 objects. Events and tickets. User will add new event and will select number of tickets for that event. Then I will be creating an entry in Event table. Also depending on number of tickets for that event, I will be creating so many entries in the tickets table. I am confused whether this logic of creating tickets when event gets created should be there in servlets or in the session bean. I have separate session bean for event and ticket. I am not sure if I should have 2 session beans or just 1 bean. Any pointers on this will be really helpful.

Code

@Entity
public class Event {    
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long eventId;
private String name;
@OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
private Set<Ticket> tickets;

    //getter and setters here
}    

@Entity
public class Ticket {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long ticketId;
@ManyToOne
@JoinColumn(name = "event_id", nullable=false)
private Event event;

//getters and setters
 }
  • 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-04T02:05:10+00:00Added an answer on June 4, 2026 at 2:05 am

    Your main logic should be in your EJBs, not in your controllers/servlets. Your EJBs should provide methods for your main use cases. You should only put presentation logic in servlets, formatting data for display and handling user actions.

    See also: Session Facade pattern

    As for the number of beans, that is your choice, you can start with one and refactor if it gets too messy.

    Also, I’m not sure you should be creating tickets when you create an event. An event can have a field that says how many tickets are available, and you create a ticket when a user buys it, or something like that.

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

Sidebar

Related Questions

Please best practice and 'how to' for using enum with jpa as a data
I'm using JPA with with Google App Engine. Let's say I have a very
In my application am using JPA entity manager to persist data/fetch data. em.executeQuery(select *
This is similar to How to cascade persist using JPA/EclipseLink I have to entities
I have created a simple java web (Vaadin) application project using JPA and it
Is there any way if executing batch updates (EntityManager persist() or merge()) using JPA
Is there way to map immutable Value objects like email address using JPA? @Immutable
I'm currently working on a desktop application using JPA/Hibernate to persist data in a
I'm using JPA to load and persist entities in my Java EE-based web application.
I am getting NonUniqueObjectException when i persist an object using JPA. The object where

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.