Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
kevinhooke / gist:85d5b2d5864fd9835cc4
Created July 2, 2015 20:54
Standalone persistence.xml against MySQL
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>list entities here if running as standalone app</class>
<properties>
@kevinhooke
kevinhooke / gist:5e577a882b13ca8ed121
Created July 2, 2015 20:57
Initialize standalone PersistenceManager for standalone app
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(exampleEntity);
em.getTransaction().commit();
@kevinhooke
kevinhooke / gist:89f2e10c13dce8a32ed4
Created July 2, 2015 20:58
JPA create a copy of existing entity using detach()
ExampleA a = new ExampleA();
em.getTransaction().begin();
em.persist(a);
em.getTransaction().commit();
// ...
em.getTransaction().begin();
em.detach(a);
@kevinhooke
kevinhooke / gist:90351b04b0ea9a34c3e3
Created July 2, 2015 21:00
JPA 2.0 with HIbernate 3.5.6 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kh.jpa</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
@kevinhooke
kevinhooke / gist:3dc73d6db589fd47f829
Created July 14, 2015 17:57
tcpdump for all tcp on if eth0
tcpdump -i eth0 tcp
@kevinhooke
kevinhooke / gist:f5e2f30f1ed12fea1229
Last active August 29, 2015 14:24
centos 7 useful network commands
#restart network
sudo /etc/init.d/network restart
#firewalld stop|start
sudo systemctl firewalld.service stop|start|status
firewall-config
- add port for 7001 for WebLogic access (zone=public, port, add 7001/tcp)
@kevinhooke
kevinhooke / gist:bc3c029d4db80a26d28e
Last active August 29, 2015 14:27
Spring Transaction api - check tx status
//check is active
TransactionSynchronizationManager.isActualTransactionActive();
//get status
TransactionStatus status = TransactionAspectSupport.currentTransactionStatus();
@kevinhooke
kevinhooke / gist:44b951537037954492c0
Created September 4, 2015 23:38
Hibernate Session from Entity Manager
Session s = (Session)em.getDelegate();
<logger name="org.hibernate.SQL"> <!-- in persistence.xml can also do property name="hibernate.show_sql" value="true" -->
<level value="debug"/>
</logger>
<logger name="org.hibernate.type">
<level value="trace"/>
</logger>
@kevinhooke
kevinhooke / gist:753ad18d01b23c97b351
Created September 15, 2015 17:16
Hibernate 3.3 second level cache config with ehcache
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<!-- not used in this version 3.3 -->
<!-- <property name="hibernate.cache.provider_class" value="org.hibernate.cache.hibernate.EhCacheProvider" /> -->
<!-- <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>