Hibernate Tutorial 13 - One To One Mapping

preview_player
Показать описание
One to one mapping of entities.
Рекомендации по теме
Комментарии
Автор

Hi This is the best Hbernate/JPA tutorial out there. Hats off man!! keep up the good work

ujjvalsharma
Автор

You can use ctrl+Shift+O for importing all the respective classes.

shivangigupta
Автор

Thanks alot for all your videos for Hibernate and Spring. It helped me alot.

noshortcutforsuccess
Автор

if anyone gets the error which is " Exception in thread "main" Unknown column 'vehicle_vehicleId' in 'field list' ", the solution is you should change property name="hbm2ddl.auto" from create to update .

emreverim
Автор

many people seem to have problems, consider dropping all tables manually, and use following annotation instead of just @OneToOne

knrd
Автор

Hi,

How to create 2 separate sequence ID, both the user id and the vehicle id gets their next val using  the same sequence... ?

jayanthbabu
Автор

Is the session.save(vehicle) is stille needed after you added @OneToOne ?

SuperNunien
Автор

Hello Koushik, in the example here, there is a possibility that one car can be owned by many user since, vehicle_id is FK (and not unique) in the user_detail table.

tipu
Автор

hey ! all of your videos are awesome...very thanks :)

arunp
Автор

if you have been following the tutorial, you have other tables depend on user_details, so when hibernate tries to delete user_details, it cannot, but it doesn't report the error either. so you ended up with an old user_details table with no vehicle_id column. Try to manually drop all your tables, try to drop user_details table first and you will see what I am talking about.

wenhoujx
Автор

 I get following ERROR: "Could not determine type for: com.mydomain.hibernate.dto.Vehicle, at table: USER_DETAILS, for columns:

Sagittarius
Автор

Please use @OneToOne(cascade = {CascadeType.ALL})
above declaring the Vehicle in Users class.

rohansharma
Автор

Some options to try:
 Specify the @Table annotation and give it a name of Vehicle OR
 Change the hbm2ddl.auto to "update"

starun
Автор

I have a Question: Don't you need @OneToOne in Vehicle entity too? If I am looking at it the correct way, ifa user puts a repeated vehicle ID into User_details table it will become a "Many To One" Relationship. Is it the other way around?

errrzarrr
Автор

If we try this in HibernateTest class:

UserDetails user = new UserDetails();
user.setUserName("First User");

UserDetails user2 = new UserDetails();
user2.setUserName("Second User");

Vehicle vehicle = new Vehicle();


user.setVehicle(vehicle);
user2.setVehicle(vehicle);

It will add both users in the table User_Details and both of them will have VEHICLE_ID = 1. But it shouldn't be possible in One-To-One relationship: Only one user can be connected with only one vehicle, and only one vehicle can be connected with only one user. Right?

LikeYouC
Автор

Hi your videos are great, but i have a question:
When i do the Reverse Engineer in MySQL (Workbench), the diagram shows me a relationship OnetoMany; why?
I really do all the things in the video :D

wombstrat
Автор

I'm getting the following error: Caused by Unknown column 'vehicle_vehicleId' in 'field list'! Can someone help me out?

mdc
Автор

if you have an error then use this annotation after @ID ;
@GeneratedValue(strategy = GenerationType.IDENTITY)

despotjc
Автор

i have same problem also create property in the xml configuration file appear to be not working it act like upgrade

Oprofs
Автор

So far I have been following everything you've done and successfully did it myself as well. But the code for this video gives me the following error? Can you please help?
Exception in thread "main" Unknown column 'vehicle_vehicleId' in 'field list'

recoveringheart