This repository was archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
123 lines (83 loc) · 3.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
This repository is basically a Maven wrapper around the original networking
extension written by Russell Francis and hosted at the Mercurial repository over
here:
https://hg.metro-six.com/public/pg-inet-types/
The official documentation for this is here:
http://www.metro-six.com/products/labs/pg-inet-types
In advance, this repository provides some extended means like integration into
OSGi runtime environments as well as other code extensions to the original.
Please visit the wiki for more information:
https://github.com/ancoron/pg-inet-maven/wiki
So, let's get started with using PostgreSQL network types within JPA:
1.) Configure this repository (if not already available):
<repository>
<id>sonatype-nexus-releases</id>
<name>Release artifacts</name>
<url>https://oss.sonatype.org/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
2.) Add a new dependency to your JPA project:
<dependency>
<groupId>org.ancoron.postgresql</groupId>
<artifactId>org.ancoron.postgresql.jpa</artifactId>
<version>9.1.901.jdbc4.1-rc9</version>
</dependency>
3.) Enabling type mapping to the database
3. a) Using explicit EcliseLink Converters:
import org.ancoron.postgresql.jpa.IPNetwork;
import org.ancoron.postgresql.jpa.eclipselink.NetworkConverter;
import org.eclipse.persistence.annotations.Convert;
import org.eclipse.persistence.annotations.Converter;
// ...
@Entity
@Table(name="test_entity_network")
@Converter(name="netConverter", converterClass=NetworkConverter.class)
public class NetworkTestEntity implements Serializable {
@Column(name="c_network", nullable=false)
@Convert("netConverter")
private IPNetwork network;
// ...
}
3. b) Using automatic conversion (keeps your Entities at pure javax.persistence):
import java.net.InetAddress;
// ...
@Entity
@Table(name="test_entity_ip")
public class IPTestEntity implements Serializable {
@Column(name="c_ip")
private InetAddress ip;
// ...
}
Now to enable the automatic mapping for the java.net.InetAddress data type
simply add this to your persistence.xml:
...
<property name="eclipselink.session-event-listener"
value="org.ancoron.postgresql.jpa.eclipselink.ConverterInitializer"/>
...
4.) If you are running your application inside an application server please
make sure that you use the appropriate ServerPlaftorm with Eclipselink,
because we have to unwrap the wrapper-connections established by the app server,
e.g. for GlassFish:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="PGNetworkUnit" transaction-type="JTA">
<jta-data-source>java:app/jdbc/NetworkTestDS</jta-data-source>
<!--
...classes...
-->
<properties>
<property name="eclipselink.target-server" value="SunAS9"/>
<!--
...other properties...
-->
</properties>
</persistence-unit>
</persistence>
Now you should be all set.
Have fun!