Logging by Log4j using xml file:
Logging empowers the software engineer to compose the log points of interest into a document for all time. Log4j and Logback structures can be utilized as a part of sleep system to help logging.- By log4j.xml file (or)
- By log4j.properties file
log4j.xml:
JAVA Tutorial Video
[embed]https://www.youtube.com/watch?v=Mb8nG-NH6gg&t=2835s[/embed]- By log4j.xml file
- By log4j.properties file
- Table Per Concrete class
- Table Per Subclass
In the past page, we have mapped the legacy progressive system with one table just utilizing xml document. Here, we will play out this undertaking utilizing explanation.
You have to utilize
@Inheritance(strategy=InheritanceType.SINGLE_TABLE), @DiscriminatorColumn and @DiscriminatorValue explanations for mapping table per progression technique.
If there should arise an occurrence of table for each pecking order, just a single table is required to delineate legacy chain of command. Here, an additional segment (otherwise called discriminator segment) is made in the table to recognize the class.
Hibernate Table Per Hierarchy using Annotation- Create the persistent classes
- Create the configuration file
- Create the class to store the fetch the data
Now the configuration file will look like this: |
class="java" >3) Create the class that stores the persistent object File: StoreTest.javapackage com.javaspot.mypackage;import org.hibernate.*;import org.hibernate.cfg.*;public class StoreData {public static void main(String[] args) {AnnotationConfiguration cfg=new AnnotationConfiguration();Session session=cfg.configure("hibernate.cfg.xml").buildSessionFactory().openSession(); Transaction t=session.beginTransaction();Employee e1=new Employee();e1.setName("sonoo");Regular_Employee e2=new Regular_Employee();e2.setName("Vivek Kumar");e2.setSalary(50000);e2.setBonus(5);Contract_Employee e3=new Contract_Employee();e3.setName("Arjun Kumar");e3.setPay_per_hour(1000);e3.setContract_duration("15 hours");session.persist(e1);session.persist(e2);session.persist(e3);t.commit();session.close();System.out.println("success");}} Table Per Concrete class using Annotation:If there should be an occurrence of Table Per Concrete class, tables are made per class. So there are no nullable esteems in the table. Weakness of this approach is that copy sections are made in the subclass tables.Here, we have to utilize @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) comment in the parent class and @AttributeOverrides explanation in the subclasses.@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) determines that we are utilizing table per solid class methodology. It ought to be determined in the parent class as it were.@AttributeOverrides characterizes that parent class characteristics will be overriden in this class. In table structure, parent class table sections will be included the subclass table.Table Per Subclass; update org.hibernate.dialect.Oracle9Dialect jdbc:oracle:thin:@localhost:1521:xe system oracle oracle.jdbc.driver.OracleDriver class="com.javaspot.mypackage.Employee"/> class="com.javaspot.mypackage.Contract_Employee"/> class="com.javaspot.mypackage.Regular_Employee"/> If there should arise an occurrence of Table Per Subclass, subclass mapped tables are identified with parent class mapped table by essential key and remote key relationship.
The
component of class is utilized to delineate youngster class with parent utilizing the essential key and outside key connection. In this case, we will utilize hb2ddl.auto property to create the table consequently. So we don't should be stressed over making tables in the database.
Table Per Subclass using Annotation:As we have determined before, if there should arise an occurrence of table for every subclass procedure, tables are made according to diligent classes however they are reated utilizing essential and remote key. So there won't be copy sections in the connection.
We have to indicate @Inheritance(strategy=InheritanceType.JOINED) in the parent class and @PrimaryKeyJoinColumn comment in the subclasses.