Maprow resultset rs int rownum throws sqlexception

Info icon This preview shows pages 172–185. Sign up to view the full content.

mapRow (ResultSet rs, int rowNum) throws SQLException { Todo todo = new Todo(); todo.setId(rs.getInt( "id" )); todo.setUser(rs.getString( "user" )); todo.setDesc(rs.getString( "desc" )); todo.setTargetDate( rs.getTimestamp( "target_date" )); todo.setDone(rs.getBoolean( "is_done" )); return todo; } }
Image of page 172

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Spring JDBC - RowMapper return jdbcTemplate.query( "SELECT * FROM TODO where user = ?" , new Object[] { user }, new TodoMapper()); return jdbcTemplate.queryForObject( "SELECT * FROM TODO where id=?" , new Object[] { id }, new TodoMapper())
Image of page 173
Questions What is JPA? What is Hibernate? How do you define an entity in JPA? What is an Entity Manager? What is a Persistence Context?
Image of page 174

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

JPA - Update Todo Defining an entity @Entity @Table (name = "Todo" ) public class Todo { @Id @GeneratedValue (strategy = GenerationType.IDENTITY) private int id; private String user; private String desc; private Date targetDate; private boolean isDone;
Image of page 175
JPA - Update Todo public class TodoJPAService implements TodoDataService { @PersistenceContext private EntityManager entityManager; @Override public void updateTodo (Todo todo) { entityManager.merge(todo); }
Image of page 176

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Questions How do you map relationships in JPA? What are the different types of relationships in JPA? How do you define One to One Mapping in JPA? How do you define One to Many Mapping in JPA? How do you define Many to Many Mapping in JPA?
Image of page 177
One to One Relationship @Entity public class Passport { .... // Inverse Relationship // bi-directional OneToOne relationship // Column will not be created in the table // Try removing mappedBy = "passport" => You will see that s // will be created in passport @OneToOne (fetch = FetchType.LAZY, mappedBy = "passport" ) private Student student; @Entity @Table (name = "Student" ) public class Student { @OneToOne private Passport passport;
Image of page 178

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

One to Many Relationship @Entity public class Project { @OneToMany (mappedBy = "project" ) private List<Task> tasks; @Entity public class Task { @ManyToOne @JoinColumn (name= "PROJECT_ID" ) private Project project;
Image of page 179
Many to Many Relationship @Entity public class Project { @ManyToMany // @JoinTable(name="STUDENT_PROJ", // [email protected](name="STUDENT_ID"), // [email protected](name="PROJECT_ID")) private List<Student> students; public class Student { @ManyToMany (mappedBy = "students" ) private List<Project> projects;
Image of page 180

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Questions How do you define a datasource in a Spring Context? What is the use of persistence.xml How do you configure Entity Manager Factory and Transaction Manager? How do you define transaction management for Spring – Hibernate integration?
Image of page 181
Defining a Data Source #HSQL in-memory db db.driver=org.hsqldb.jdbcDriver db.url=jdbc:hsqldb:mem:firstdb db.username=sa db.password= <bean id = "dataSource" class = "com.mchange.v2.c3p0.ComboPooledDa destroy-method = "close" > <property name = "driverClass" value = "${db.driver}" /> <property name = "jdbcUrl" value = "${db.url}" /> <property name = "user" value = "${db.username}" /> <property name = "password" value = "${db.password}" /> </bean>
Image of page 182

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Configuring Hibernate src\main\resources\config\hibernate.properties hibernate.dialect=org.hibernate.dialect.HSQLDialect hibernate.show_sql=false hibernate.format_sql=false hibernate.use_sql_comments=true
Image of page 183
persistence.xml src\main\resources\META-INF\persistence.xml <?xml version="1.0" encoding="UTF-8"?>
Image of page 184

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 185
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '18
  • LN Rao
  • public class, Spring Framework, Spring Boot, Spring Security

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern