[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Partitioning with unidirectional associations
|
I think my question should be expanded a bit as I've run across a curious situation. I'm trying to model something after the example found on:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Partitioning
I have a slightly more simplistic example. My persistence unit looks like:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="sample" transaction-type="RESOURCE_LOCAL">
<class>samples.model.EmailAddress</class>
<class>samples.model.Customer</class>
<properties>
<property name="javax.persistence.jdbc.driver"
value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/defaultdb"/>
<property name="javax.persistence.jdbc.user" value="defaultdb"/>
<property name="javax.persistence.jdbc.password" value="defaultdb"/>
<!-- Configure default connection pool. -->
<property name="eclipselink.connection-pool.default.initial" value="1"/>
<property name="eclipselink.connection-pool.default.min" value="64"/>
<property name="eclipselink.connection-pool.default.max" value="64"/>
<!-- Configure 2nd database connection pool. -->
<property name="eclipselink.connection-pool.node2.url"
value="jdbc:mysql://localhost:3306/node2"/>
<property name="eclipselink.connection-pool.node2.user" value="node2"/>
<property name="eclipselink.connection-pool.node2.password"
value="node2"/>
<property name="eclipselink.connection-pool.node2.initial" value="1"/>
<property name="eclipselink.connection-pool.node2.min" value="64"/>
<property name="eclipselink.connection-pool.node2.max" value="64"/>
<!-- Default partioning to replication to allow DDL to be sent to all nodes -->
<property name="eclipselink.partitioning" value="Replicate"/>
</properties>
</persistence-unit>
</persistence>
Customer has the following partitions and OneToMany to EmailAddress:
@Entity
@Table(name = "customer")
@UnionPartitioning(
name = "UnionPartitioningAllNodes",
replicateWrites = true,
connectionPools = {"default", "node2"})
@ReplicationPartitioning(name="Replicate", connectionPools={"default","node2"})
@HashPartitioning(name="HashPartitionByCustomerNamespace", partitionColumn=@Column(name="NAMESPACE"), connectionPools={"default","node2"}, unionUnpartitionableQueries = true)
@Partitioned("HashPartitionByCustomerNamespace")
public class Customer implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private int namespace = 0;
private String firstName;
private String lastName;
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL)
private List<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
EmailAddress then has:
@Entity
@Table(name = "email_address")
@HashPartitioning(name="HashPartitionByEmailNamespace", partitionColumn=@Column(name="NAMESPACE"), connectionPools={"default","node2"}, unionUnpartitionableQueries = true)
@Partitioned("HashPartitionByEmailNamespace")
public class EmailAddress {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String address;
private String type;
private int namespace = 0;
@ManyToOne
private Customer customer;
I have a simple test that just creates a new Customer and adds an email address and then I try to persist this.
The hash passes in simple 0 or 1 in namespace to determine which datastore to save the record in. If I try to persist Customer in one datastore and EmailAddress in the other, I get the following:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`default`.`email_address`, CONSTRAINT `FK_email_address_CUSTOMER_ID` FOREIGN KEY (`CUSTOMER_ID`) REFERENCES `customer` (`ID`))
I would assume this would work as the sample code at the link above seems to suggest. Is there something I am doing wrong here that is obvious? I should note I am creating the entity manager via Spring as follows:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="sample"/>
<property name="persistenceProvider" ref="eclipseLinkPersistenceProvider"/>
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform"
value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
</bean>
Thanks in advance for the help.
Mike Key
On Mar 22, 2012, at 1:59 PM, Mike Key wrote:
> Forgive me if this has been answered here already. I am setting up some partitioning schemes in Eclipselink 2.3.2 with JPA. It would seem my simple example will only work for One-To-Many relationships if the association is bi-directional. Is this by design? It seems to make sense logically that it is, however I am wondering if uni-directional associations are supported in any way for partitioning?
>
> Thanks for any help.
>
>
Attachment:
signature.asc
Description: Message signed with OpenPGP using GPGMail