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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:36:50+00:00 2026-05-27T19:36:50+00:00

I have 2 questions: suppose we have one entity named class and another called

  • 0

I have 2 questions: suppose we have one entity named class and another called student. each class has onetomany students.

public class Clas implements Serializable {
@Id
  @GeneratedValue(strategy=GenerationType.SEQUENCE)
private int id;
@OneToMany(cascade=CascadeType.ALL)
Collection<Student> students;
public clas(){
super();
}
 ..... getters and setters
}

q1: i get the exception there are no fields to be mapped because of sequence strategy, when adding any other column like String name, it works, but i don’t need that field what can i do ?

q2. the ids is autogenerated, and i want to query all students in class c1, but i don’t has the id of this class, how to get such query without using id? or how to get database entity id to query on it ?

iam working with mysql server glassfish v2.1 toplink jpa 1.0

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-27T19:36:51+00:00Added an answer on May 27, 2026 at 7:36 pm

    Regarding your second question: when you create a Clas instance, persist it, and flush, the ID is autogenerated, and assigned to the ID field of the Clas instance. Since flushing happens automatically at the end of the transaction, calling this transactional session bean method will return a Clas instance with an ID:

    public Clas createClas() {
        Clas c = new Clas();
        // call setters to populate the clas
        entityManager.persist(c);
        return c;
    }
    

    Caller code:

    Clas c = mySessionBean.createClas();
    int clasId = c.getId(); // clasId is the generated ID of the created Clas.
    

    Once you have the clas ID, and want to get all its student, just do the following:

    public Collection<Student> getStudentOfClas(int clasId) {
        Clas clas = entityManager.find(Clas.class, clasId);
        return clas.getStudents();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
I have two questions about java.awt.Shape . Suppose I have two Shape s, shape1
I have some questions about using MySQLi queries, and related memory management. Suppose I
I have questions about System.Threading.ThreadStart Class : where can I find its specifications (
I have a table called Basic , start_time is one field with type :VARCHAR(5),
I know similar questions have been asked before, but I can't find one that
Suppose I have an abstract base class, that just defines a container on which
Suppose I have following inheritance tree: SDLBullet inherits from Bullet inherits from Entity EnemyBullet
Suppose i have two tables with one to many relationship (association in EF 4.1)
hi , I have 2 related questions. 1)suppose we have: string strMessage=\nHellow\n\nWorld; console.writeln(strMessage); Result

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.