public void testSerializableToBlob() throws Exception { Book book = new Book(); Editor editor = new Editor(); editor.setName("O'Reilly"); book.setEditor(editor); book.setCode2(new char[] {'r'}); Session s; Transaction tx; s = openSession(); tx = s.beginTransaction(); s.persist(book); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); Book loadedBook = (Book) s.get(Book.class, book.getId()); assertNotNull(loadedBook.getEditor()); assertEquals(book.getEditor().getName(), loadedBook.getEditor().getName()); loadedBook.setEditor(null); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); loadedBook = (Book) s.get(Book.class, book.getId()); assertNull(loadedBook.getEditor()); tx.commit(); s.close(); }
public void testClob() throws Exception { Session s; Transaction tx; s = openSession(); tx = s.beginTransaction(); Book b = new Book(); b.setShortDescription("Hibernate Bible"); b.setFullText("Hibernate in Action aims to..."); b.setCode(new Character[] {'a', 'b', 'c'}); b.setCode2(new char[] {'a', 'b', 'c'}); s.persist(b); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); Book b2 = (Book) s.get(Book.class, b.getId()); assertNotNull(b2); assertEquals(b2.getFullText(), b.getFullText()); assertEquals(b2.getCode()[1].charValue(), b.getCode()[1].charValue()); assertEquals(b2.getCode2()[2], b.getCode2()[2]); tx.commit(); s.close(); }