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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:41:59+00:00 2026-05-30T13:41:59+00:00

I got a little issue with hibernate since hibernate doesn’t accept a normal sql

  • 0

I got a little issue with hibernate since hibernate doesn’t accept a normal sql query syntax. When i send my query with a select statement which should return an exact integer of 37 to the database i get nothing in return instead. This is the query in sql syntax:
“select id from tbl_employee where bsn = ‘36372837’” this returns 37. But when i execute this query from within hibernate with al the object references and crap it doesn’t work.

Please check my code and see if you know how to solve the problem:

public void RegisterWorkHours(TimeRegistration object)
    {
        EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("timereg");
        EntityManager em = emf.createEntityManager();
        try
        {


            String get_employee_id = "SELECT emp.id FROM Employee as emp WHERE emp.bsn=:bsn";
            Query employee_query = em.createQuery(get_employee_id);
            employee_query.setParameter("bsn", object.getEmployee().getBsn());
            int id = employee_query.getFirstResult();
            System.out.println("query returns employee id: " + id);
            object.getEmployee().setId(id);


            String get_project_id = "SELECT p.projectID FROM Project as p WHERE p.projectname=:projectname";
            Query project_query = em.createQuery(get_project_id); 
            project_query.setParameter("projectname", object.getProject().getProjectname());
            int projectid = project_query.getFirstResult();
            System.out.println("query returns projectid: " + projectid);
            object.getProject().setProjectID(projectid);

            em.getTransaction().begin();



                em.persist(object);
                em.getTransaction().commit();

        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }
    }

Employee class:

@Entity
@Table(name = "tbl_employee")
public class Employee
{
    @Id
    @SequenceGenerator(name="employeeSequence", sequenceName="SEQ_EMPLOYEE", allocationSize =1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="employeeSequence")
    @Column(name="id")
    private int id;


    @Column(name = "bsn")
    @NaturalId
    private String bsn;

    @Column(name = "first_name")
    private String firstname;

    @Column(name = "last_name")
    private String lastname;

    @Column(name="birth_date")
    private String birthDate;

    @Column(name="address")
    private String address;

    @Column(name="house_number")
    private String houseNumber;

    @Column(name="city")
    private String city;

    @Column(name="zip")
    private String zip;

    //Constructor
    protected Employee() {}

    public Employee(String bsn, String firstname, String lastname)
    {
        setBsn(bsn);
        setFirstname(firstname);
        setLastname(lastname);

    }
    public Employee(String bsn, String firstname, String lastname, String address, String housenumber)
    {
        setBsn(bsn);
        setFirstname(firstname);
        setLastname(lastname);
        setAddress(address);
        setHouseNumber(housenumber);
    }
    public Employee(String bsn, String firstname, String lastname, String address, String housenumber, String zip, String city)
    {
        setBsn(bsn);
        setFirstname(firstname);
        setLastname(lastname);
        setAddress(address);
        setHouseNumber(housenumber);
        setZip(zip);
        setCity(city);
    }

    //The rest is one big list of getters and setters.
}

TimeRegistration class

@Entity
@Table(name = "tbl_timeregtest")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class TimeRegistration
{
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private Project project;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private Employee employee;

    @Id
    @SequenceGenerator(name="timeregSequence", sequenceName="SEQ_TIMEREG", allocationSize =1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="timeregSequence")
    @Column(name="ID")
    private int ID;

    @Column(name="date")
    private String date;


    @Column(name="hours")
    private int hours;

    //Constructor
    protected TimeRegistration() {}

    public TimeRegistration(Project project, Employee employee, String date, int hours  )
    {
        setProject(project);
        setEmployee(employee);
        setDate(date);
        setHours(hours);
    }

//the rest is all getter setter stuff
}

main void

public class Main
{

    public static void main(String [ ] args)
    {
        Persistence persistence = new Persistence();
        Project project = new Project("AlphaMouse", "11-2-2013", "12-4-2019");
        Employee employee = new Employee("398723912", "Stoel",  "Stra");    
        TimeRegistration register = new TimeRegistration(project, employee, "21-2-2024", 8);
        persistence.RegisterWorkHours(register) ;
}}

Thanks in advance,
Benjamin

  • 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-30T13:42:00+00:00Added an answer on May 30, 2026 at 1:42 pm

    You are using the method getFirstResult().
    But this method returns the position (integer) of the record in the table.

    To retrieve the record (object), you should use getSingleResult() instead.

    See http://docs.oracle.com/javaee/6/api/javax/persistence/Query.html.

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

Sidebar

Related Questions

Got a little issue where my client is pasting in content from Word into
I've got a little issue with rails, I want to be able to do
I have a little issue. I have to send NSDate as parameter to soap
I'm working on a little Websockets demo and I've got a scope issue I
I've been fumbling with this issue for a bit. I've got a lovely little
I'm new in Reporting services and got little confused. in the screen shot you
Got my little mechanize code: br.open('http://tumblr.com/customize'); print br.response().read() print br.form['edit_tumblelog[cname]'] # there definitely is
I got a little curious after reading this /. article over hijacking HTTPS cookies.
I got a little stuck and I'm hoping someone can point me in the
i`ve got a little problem with LINQ. I read out some information via XML-RPC.

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.