The flashcards below were created by user Anonymous on FreezingBlue Flashcards.

  1. hbm2ddl.auto - create means the schema is going to be created.

  2. hbm2ddl.auto - update which is not going to delete and update the table.

  3. show_sql set to true. It is helpful how hibernate queries

  4. @Entity(name="USER_DETAILS") - means the model is saved as the table name.

  5. @Column (name="USER_NAME")
    • private String userName;
    • on top of the variable.

    • @Id
    • @Column(name="USER_ID")
    • private int userId;

    • you can put the annotation on top of getUserName() But in this case if something is added to in the getter
    • like "My getter". The same will be added.
    • @Id
    • @Column(name="USER_NAME")
    • private String getUserName(){
    • Return user_name +" from getter";
    • }
    • if it is annoated in the above way then we have user_name +" from getter" in the table and NOT just user_name
  6. session.close(); what does it do?
    Usually in the finally block.

    • Next time you open hibernate you dont have to use sessionFactory. Since SessionFactory is costly you create
    • only one for an application.
    • user = (User_Details)session.get(UserDetails.class,1);
    • This will pull up the record based on primary key value.
    • It brings the whole object.
    • user.getUserName(); brings the value.

    • Natural keys - columns that are unique and have a business purpose.
    • Surrogate key - no business value but act as a primary key.
    • In the case of surrogate keys you dont have to take care of incrementing or the key id every time for insertion.
    • Hibernate does it it for you. It is denoated by @GeneratedValue
    • @Id @GeneratedValue(strategy=GenerationType.AUTO) is default.
    • AUTO, IDENTITY, SEQUENCE, TABLE is based on a table if primary key
  7. what if one of the memeber variable is an object?
    • User class - instead of a simple string. it is an object.
    • Adress - Street, city, state Pincode. we are going to use Embeddable and Embedded.
  8. what is a value object?
  9. does not have any meaning on its own but adds meaning to a different object.
    • Address of this user. Address doesent make it sense on its own.
    • Enity has a meaning on its own. Value object has a meaning on its own.
  10. Eg of value object
    • For the user create an Address class.
    • private String street;
    • private String city;
    • private String state
    • private String country;
  11. and mark it as @Embeddable.
    • In the UserDetails.class create an Address object and make it @Embedded.
    • Create a new address object in the main().
  12. Address addr = new Address();
    • addr.setStreet("Lyons");
    • addr.setCity("coconut creek");
  13. user.setAddress(addr);
  14. The embeddable object becomes a part of the address table.
    The columns of the address are part of the Userdetails object.
  15. How to configure the column names of embedded object?
    • 1) Go to the subobject or Embeddable object
    • @Column(name="STREET_NAME")
    • pirvate String Street;
  16. What if there are two embedded objects inside an embeddable? when there are two subobjects
    like home address and office address. The same columns cannot be used becuase the second object will overwrite
    the first object. What do you do in such a scenario?
  17. You use @AttributeOveride (name="street", column=@Column(name="HOME_STREET_NAME"))
  18. If you want to override many attributes? how do you do it?
    • Because attributeOverride is just for one column.
    • @AttributeOverrides({
    • @AttributeOveride (name="street", column=@Column(name="HOME_STREET_NAME")),
    • @AttributeOveride (name="city", column=@Column(name="HOME_STREET_CITY")),
    • @AttributeOveride (name="street", column=@Column(name="HOME_STREET_CITY")),
    • })
  19. what is an EmbeddedId?
    • Is for objects that are going to act as primary for another object.
    • A combinations os members that act as primary key for another object.
Card Set
Kaushik tutorials.
Show Answers