This is NOT the final doc
Put here anything useful for development
- Download and install MySQL: click here
- Start MySQL (May need to config global variable)
- Create a table in database:
CREATE DATABASE igrader;
USE igrader;
- Init the database with our scheme: Run code in PonyORM
- Copy
src/hibernate.cfg.xml.template
tosrc/hibernate.cfg.xml
- Edit
src/hibernate.cfg.xml
: put username and password
<property name="connection.username">YOUR USERNAME</property>
<property name="connection.password">YOUR PASSWORD</property>
- On IDEA's left hand "Project" panel, right click on project folder (
iGrader
), select Add Framework Support... - In the popup menu, scroll to bottom and select Hibernate
- On right hand side, click on download if you don't have one. Otherwise select the existing library. Click OK.
- In menu bar, Files - Project Structure
- Do as follows to add the config file. Click OK.
- Download jdbc library with this link. Unzip to get the
.jar
file. - In IDEA, Files - Project Structure
- In Library tab:
- Browse and select the
.jar
file you just downloaded - Click OK to save the setting.
Run src/Test/DatabaseTest::Main
, if no error, then you're good to go!
Use classes in src.Database
to talk with database. Database means Data Access Object.
Student stu = new Student("U1234567", new Name("Alice"), false);
stu.save();
DAO dao = new DAO();
Student stu = DAO().findById(Student.class, "U123456789");
stu.setGrad(false);
stu.update(); // Database will be updated
stu.getName().getFirstName(); // "Alice"
stu.getName().setFirstName("Bob");
stu.refresh(); // Object will be updated by database
stu.getName().getFirstName(); // "Alice"
new Database().delete(Student.class, stu.getId());
List result = new Database().query("some hql query");