Hibernate Query, how to group different tables?

Im pretty new to databases, and programming in general, i tried everything but could not come up with a solution, my problem is: I have 2 tables in my database:

  • Cars
  • Model

in my Cars table i have 3 columns: *modelID *carName *carsSold

and the Model table has 3 columns: *modelID *modelName *modelYear

Now my program has a button that says Group by Model, when the user clicks it has to show the information grouped by the Model, like:

  1. Model ID : 1022

    • Model Name: Audi
    • Car Name: A3

    • Year: 2001

    • Cars sold: 120

Everything is ready, im just lost at the HQL query


It seems like you have some problems with your database schema.

What is the primary key for car? What is the mapping relationship between car and model?

The way it reads, you have two tables with info such as:

modelID | carName | carsSold
1022    | A3    | 120

modelID | modelName | modelYear
1022    | Audi      | 2001

This does not seem like a logical arrangement for the data you are trying to represent.

I'm not exactly sure what you are trying to accomplish. I'm also not sure that "group by" is what you are looking for.

If this is really your entire database structure, and you are not planning anything else, why not have one table? table SALE(id, modelName, carName, modelYear, carsSold) or something like that. With this table, the HQL is simply a select and then display the information from the model object.

Maybe if you clarified what the requirements are for your data I could give you some better direction on where to go with your database.

Need Your Help

How do you unit test formsets in Django?

django unit-testing formset

Ok, so i need to unit test a view, more precise form in a view . So i create such a unit test.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.