Im using hibernate and i tried to do the following

session.get(Company.class, 1);

After i executed the statement above i got this strange select statement generated by hibernate

        company0_.Company_ID as Company1_31_4_,
        company0_.version as version2_31_4_,
        company0_.Address_ID as Address5_31_4_,
        company0_.Company_Code as Company3_31_4_,
        company0_.Company_Name as Company4_31_4_,
        company0_.Phone_ID as Phone6_31_4_,
        address1_.Address_ID as Address1_0_0_,
        address1_.version as version2_0_0_,
        address1_.Company_ID as Company4_0_0_,
        address1_.Address as Address3_0_0_,
        company2_.Company_ID as Company1_31_1_,
        company2_.version as version2_31_1_,
        company2_.Address_ID as Address5_31_1_,
        company2_.Company_Code as Company3_31_1_,
        company2_.Company_Name as Company4_31_1_,
        company2_.Phone_ID as Phone6_31_1_,
        phone3_.Phone_ID as Phone1_77_2_,
        phone3_.version as version2_77_2_,
        phone3_.Company_ID as Company5_77_2_,
        phone3_.Fax_Number as Fax3_77_2_,
        phone3_.Phone_Number as Phone4_77_2_,
        company4_.Company_ID as Company1_31_3_,
        company4_.version as version2_31_3_,
        company4_.Address_ID as Address5_31_3_,
        company4_.Company_Code as Company3_31_3_,
        company4_.Company_Name as Company4_31_3_,
        company4_.Phone_ID as Phone6_31_3_ 
        testing.Company company0_ 
    left outer join
        testing.Address address1_ 
            on company0_.Address_ID=address1_.Address_ID 
    left outer join
        testing.Company company2_ 
            on address1_.Company_ID=company2_.Company_ID 
    left outer join
        testing.Phone phone3_ 
            on company0_.Phone_ID=phone3_.Phone_ID 
    left outer join
        testing.Company company4_ 
            on phone3_.Company_ID=company4_.Company_ID 

What is wrong here?

You dont use it well, try like this:

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

List<Company> lista = new ArrayList<Company>();
Criteria crit = session.createCriteria(Company.class);

if (true){ // you can add restriction like this name is passed in to method...
       crit.add("name", name).ignoreCase());
lista = crit.list();

And you can see a lot of examples on this link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.