Skip to content

Latest commit

 

History

History

jpa

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

esc-jpa

Java Persistence API (JPA) based implementation of the event store commons api.

Entity types

There are two different scenarios:

  1. Streams that require one or more discriminator columns
  2. Streams without the need for a discriminator column

An example for streams with discriminator columns is the below mentioned "Vendor" aggregate. There is only one stream entity (table) and one event entity (table) for all vendors. The vendor's ID is used as discriminator column to distinguish events for the different vendors.

The discriminator is coded in the stream identifier. An example of an identifier with discriminator column is the AggregateStreamId and another one for an identifier without a discriminator is the SimpleStreamId.

The good new is: There is no need to create any entities if you don't need a discriminator column. There are already two predefined entites NoParamsEvent and NoParamsStream that will be used automatically in this case. For streams that require discriminator columns you have to create two entity classes ("XyzEvent" + "XyzStream") named as described below.

Custom naming of tables and entities

You can use JpaStreamId to define the names of your stream entities and classes. There are two predfined classes SimpleJpaStreamId and ProjectionJpaStreamId that already implement this interface.

Default naming conventions

If you don't define an explicit stream name using a JpaStreamId, a strict default naming convention applies. You have to name your tables and identifiers exactly as described below otherwise it will not work.

StreamId

Use a camel case stream identifier name that ends not on 'Stream', 'Streams', 'Event' or 'Events'.

StreamId streamId = new AggregateStreamId("YourSelectedName", discriminatorValue);

Event entity

Table name is the same as the stream identifier plus '_EVENTS' and uses an 'underscore' for replacing camel case parts. Class name is the same as the stream identifier plus 'Event' (Note that there is no 's' at the end!).

@Table(name = "YOUR_SELECTED_NAME_EVENTS")
@Entity
public class YourSelectedNameEvent extends JpaStreamEvent { 
    // ... 
}

Stream entity

Table name is the same as the stream identifier plus '_STREAMS' and uses an 'underscore' for replacing camel case parts.
Class name is the same as the stream identifier plus 'Stream' (Note that there is no 's' at the end!).

@Table(name = "YOUR_SELECTED_NAME_STREAMS")
@Entity
public class YourSelectedNameStream extends JpaStream { 
    // ... 
}

Example JPA entity structure

The UML diagram shows how events of an example "Vendor" aggregate are stored in the database. A VendorStream has information about the stream itself and VendorEvent has a reference to the event table. The JpaEvent table contains the real event data.
JPA Entities