Guest User

Untitled

a guest
Jan 5th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. Exception in thread "main" java.lang.NullPointerException
  2. at yPray.services.TerminalTeamImpl.add(TerminalTeamImpl.java:25)
  3. at yPray.Application.main(Application.java:13)
  4.  
  5. @Override
  6. public void add(Team team) {
  7. Session session = HibernateUtil.getSessionFactory().openSession();
  8. Transaction tx = session.beginTransaction();
  9. session.save(team);
  10. tx.commit();
  11. session.close();
  12. }
  13.  
  14. @Entity
  15. @Table(name = "teams")
  16. public class Team {
  17. @Id
  18. @GeneratedValue(strategy = GenerationType.IDENTITY)
  19. private int idTeam;
  20.  
  21. @Column
  22. private String teamTag;
  23.  
  24. @Column
  25. private int score;
  26.  
  27. public Team(){}
  28. public Team(String teamTag){
  29. this.teamTag = teamTag;
  30. }
  31. // getters and setter
  32.  
  33. @Service
  34. public class TerminalTeamImpl implements TerminalTeam {
  35.  
  36. @Resource
  37. private TeamDaoImpl teamDao;
  38.  
  39. @Override
  40. public void add(Team team) {
  41. teamDao.add(team);
  42. }
  43.  
  44. public class HibernateUtil {
  45. private static SessionFactory sessionFactory;
  46.  
  47. private HibernateUtil(){}
  48.  
  49. public static SessionFactory getSessionFactory(){
  50. if (sessionFactory == null) {
  51. try{
  52. Configuration configuration = new Configuration().configure();
  53. configuration.addAnnotatedClass(Team.class);
  54. configuration.addAnnotatedClass(Player.class);
  55. StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
  56. sessionFactory = configuration.buildSessionFactory(builder.build());
  57. }catch (Exception e) {
  58. System.out.println("Exception!!! " + e);
  59. }
  60. }
  61. return sessionFactory;
  62. }
  63. }
  64.  
  65. <?xml version="1.0" encoding="UTF-8"?>
  66. <!DOCTYPE hibernate-configuration PUBLIC
  67. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  68. "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  69. <hibernate-configuration>
  70. <session-factory>
  71. <property
  72. name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  73. <property
  74. name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/test</property>
  75. <property name="hibernate.connection.username">root</property>
  76. <property name="hibernate.connection.password">password</property>
  77. <property name="hibernate.connection.pool_size">1</property>
  78. <property
  79. name="hibernate.current_session_context_class">thread</property>
  80. <property name="hibernate.show_sql">true</property>
  81. <property
  82. name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  83. </session-factory>
  84. </hibernate-configuration>
  85.  
  86. <build>
  87. <plugins>
  88. <plugin>
  89. <groupId>org.apache.maven.plugins</groupId>
  90. <artifactId>maven-compiler-plugin</artifactId>
  91. <configuration>
  92. <source>6</source>
  93. <target>6</target>
  94. </configuration>
  95. </plugin>
  96. </plugins>
  97. </build>
  98. <dependencies>
  99. <dependency>
  100. <groupId>mysql</groupId>
  101. <artifactId>mysql-connector-java</artifactId>
  102. <version>8.0.12</version>
  103. </dependency>
  104. <dependency>
  105. <groupId>org.hibernate</groupId>
  106. <artifactId>hibernate-core</artifactId>
  107. <version>5.3.6.Final</version>
  108. </dependency>
  109. <dependency>
  110. <groupId>org.springframework.boot</groupId>
  111. <artifactId>spring-boot</artifactId>
  112. <version>2.0.5.RELEASE</version>
  113. </dependency>
  114. <dependency>
  115. <groupId>org.springframework</groupId>
  116. <artifactId>spring-context</artifactId>
  117. <version>5.0.9.RELEASE</version>
  118. </dependency>
  119. <dependency>
  120. <groupId>org.springframework</groupId>
  121. <artifactId>spring-core</artifactId>
  122. <version>5.0.9.RELEASE</version>
  123. </dependency>
  124. <dependency>
  125. <groupId>javax.annotation</groupId>
  126. <artifactId>javax.annotation-api</artifactId>
  127. <version>1.3.2</version>
  128. </dependency>
  129. </dependencies>
  130.  
  131. public class Application {
  132. public static void main(String[] args) {
  133. Team navi = new Team("Navi");
  134. TerminalTeamImpl team = new TerminalTeamImpl();
  135. team.add(navi);
  136.  
  137. }
  138. }
Add Comment
Please, Sign In to add comment