List of usage examples for org.hibernate Session persist
void persist(Object object);
From source file:Modelo.TrabajadorDAO.java
/** * Mtodo que guarda una trabajador en la base de datos * @param trabajador /*from www . j a v a 2s. c o m*/ */ public void guardar(Trabajador trabajador) { Session session = sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); session.persist(trabajador); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } finally { session.close(); } }
From source file:Modelo.UserDAO.java
/** * Guarda a un usuario en la base de datos. * @param user/*from www . j av a 2 s .co m*/ */ public void guardar(User user) { Session session = sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); session.persist(user); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } finally { session.close(); } }
From source file:monasca.thresh.infrastructure.persistence.hibernate.AlarmSqlImpl.java
License:Apache License
private MetricDefinitionDb insertMetricDefinition(final Session session, final MetricDefinitionAndTenantId mdtid) { final String region = ""; // TODO We currently don't have region final String definitionIdStringToHash = truncateString(mdtid.metricDefinition.name, MAX_COLUMN_LENGTH) + truncateString(mdtid.tenantId, MAX_COLUMN_LENGTH) + truncateString(region, MAX_COLUMN_LENGTH); final byte[] id = DigestUtils.sha(definitionIdStringToHash); final MetricDefinitionDb metricDefinition = new MetricDefinitionDb(id, mdtid.metricDefinition.name, mdtid.tenantId, region);/*ww w .j av a2 s. c o m*/ if (session.get(MetricDefinitionDb.class, metricDefinition.getId()) == null) { session.persist(metricDefinition); return metricDefinition; } session.merge(metricDefinition); return metricDefinition; }
From source file:net.lizalab.util.jasypt.h4.ext.connectionprovider.EncryptedConnectionProviderImplIT.java
License:Apache License
private void doTest(Configuration configuration) { ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); // Try to initialize session factory. Since we have db entity creation // configured it should happen here. SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); // Test that we have a non-null session factory. assertNotNull("Expected a non-null session factory!", sessionFactory); // For some reason db entity creation errors don't get propagated so // we are still not guaranteed to be up and running, so lets do a // simple test transaction to confirm everything worked and we are // indeed connected to the database. Session session = sessionFactory.getCurrentSession(); session.beginTransaction();//from ww w.j av a2s .c om try { TestEntity testEntity = new TestEntity( "Encrypted c3p0 connection provider implementation Integration Test."); session.persist(testEntity); session.getTransaction().commit(); } finally { try { session.getTransaction().rollback(); } catch (Exception e) { } } }
From source file:net.purnama.pureff.dao.AdjustmentDao.java
public AdjustmentEntity addAdjustment(AdjustmentEntity adjustment) { Session session = this.sessionFactory.getCurrentSession(); session.persist(adjustment); return adjustment; }
From source file:net.purnama.pureff.dao.AdjustmentDraftDao.java
public AdjustmentDraftEntity addAdjustmentDraft(AdjustmentDraftEntity adjustmentdraft) { Session session = this.sessionFactory.getCurrentSession(); session.persist(adjustmentdraft); return adjustmentdraft; }
From source file:net.purnama.pureff.dao.BuyPriceDao.java
public BuyPriceEntity addBuyPrice(BuyPriceEntity buyprice) { Session session = this.sessionFactory.getCurrentSession(); session.persist(buyprice); return buyprice; }
From source file:net.purnama.pureff.dao.CurrencyDao.java
public CurrencyEntity addCurrency(CurrencyEntity currency) { Session session = this.sessionFactory.getCurrentSession(); session.persist(currency); return currency; }
From source file:net.purnama.pureff.dao.DeliveryDao.java
public DeliveryEntity addDelivery(DeliveryEntity delivery) { Session session = this.sessionFactory.getCurrentSession(); session.persist(delivery); return delivery; }
From source file:net.purnama.pureff.dao.DeliveryDraftDao.java
public DeliveryDraftEntity addDeliveryDraft(DeliveryDraftEntity deliverydraft) { Session session = this.sessionFactory.getCurrentSession(); session.persist(deliverydraft); return deliverydraft; }