Hibernate ORM SessionFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM SessionFactory class.

This code example shows how to use the following methods: getCurrentSession
		this.sessionFactory = sessionFactory;
	} 
 
	@Override 
	public Person save(Person person) {
		this.sessionFactory.getCurrentSession().save(person);
		return person;
	} 
 
	@Override 
	public Person findByName(String name) {
		return (Person) this.sessionFactory.getCurrentSession().createQuery(
			"from Person person where person.name = :name").setString("name", name).uniqueResult();
	} 
} 
Full Snippet Info
10
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getCurrentSession
	@Autowired 
	private SessionFactory sessionFactory;
 
	public void save(final PersistentScriptTemplate t)
	{ 
		sessionFactory.getCurrentSession().saveOrUpdate(t);
	} 
 
	@SuppressWarnings("unchecked") 
	public List<PersistentScriptTemplate> findAll(final Lang lang)
	{ 
		return sessionFactory.getCurrentSession()
			.createCriteria(PersistentScriptTemplate.class)
			.add(Restrictions.eq("lang", lang))
			.list(); 
	} 
 
	public PersistentScriptTemplate get(final Long id)
	{ 
		return (PersistentScriptTemplate)sessionFactory.getCurrentSession().get(
Full Snippet Info
10
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getCurrentSession
	 *  
	 * @return hibernate session 
	 */ 
	protected Session getSession()
	{ 
		return factory.getCurrentSession();
	} 
 
	/** 
	 * Load a {@link Contact} from the DB, given it's <tt>id</tt> . 
	 *  
	 * @param id 
	 *            The id of the Contact to load. 
	 * @return Contact 
	 */ 
	public Contact load(long id)
	{ 
		return (Contact)getSession().get(Contact.class, Long.valueOf(id));
	} 
 
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: openSession
	 * @param entityInterceptor Hibernate entity interceptor, or {@code null} if none 
	 * @return the new Session 
	 */ 
	@SuppressWarnings("deprecation") 
	public static Session getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor) { 
		Assert.notNull(sessionFactory, "No SessionFactory specified"); 
 
		try { 
			SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory); 
			if (sessionHolder != null && !sessionHolder.isEmpty()) { 
				if (entityInterceptor != null) { 
					return sessionFactory.openSession(sessionHolder.getAnySession().connection(), entityInterceptor); 
				} 
				else { 
					return sessionFactory.openSession(sessionHolder.getAnySession().connection()); 
				} 
			} 
			else { 
				if (entityInterceptor != null) { 
					return sessionFactory.openSession(entityInterceptor); 

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getCurrentSession
 
	} 
 
	@Test
	public void testWriteAndFlushSunnyDayHibernate4() throws Exception {
		writer.setSessionFactory(factory);
		when(factory.getCurrentSession()).thenReturn(currentSession);
		when(currentSession.contains("foo")).thenReturn(true);
		when(currentSession.contains("bar")).thenReturn(false);
		currentSession.saveOrUpdate("bar");
		currentSession.flush();
		currentSession.clear();
 
		List<String> items = Arrays.asList(new String[] { "foo", "bar" });
		writer.write(items);
	} 
 
	@Test
	public void testWriteAndFlushWithFailureHibernate4() throws Exception {
		writer.setSessionFactory(factory);
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
See Code Examples for Hibernate ORM SessionFactory Methods: