Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » tenant_id column set blank after persist(when I persist a multitenant object the column that refer the tenant go in blank)
tenant_id column set blank after persist [message #1432370] Sat, 27 September 2014 02:21
Mário Santos Sousa is currently offline Mário Santos SousaFriend
Messages: 1
Registered: September 2014
Junior Member
Hi guys!

I'm developing a multitenancy system and I'm using Single-Table Multi-Tenancy.
So when I persist a new multitenancy object the column that reference the tenant column is saved in blank and I don't know why.

I did a test but it worked well...

               HashMap<String, Integer> properties = new HashMap<String, Integer>();
		properties.put("tenant.empresa", 500);
	  
		factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,properties);
		EntityManager em = factory.createEntityManager();

		// create new 
		em.getTransaction().begin();
		Produto p = new Produto();
		p.setDescricao("test");
		
		em.persist(p);
		
		em.getTransaction().commit();
		
		em.close();

when I execute a test class the object is saved correctly with the tenant_id 500... but when the applications is running this not occur... and I'm using a similar code to do this....

I'm using JSF, Spring Framework, and PostgreSQL the tenant identifier is in session and when I need I build a EntityManager like above with tenant identifier

persistence.xml
	
	<persistence-unit name="TCC" transaction-type="RESOURCE_LOCAL">
		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		
		<class>br.com.mario.tcc.model.Funcionario</class>
		<class>br.com.mario.tcc.model.Usuario</class>
		<class>br.com.mario.tcc.model.Empresa</class>
		<class>br.com.mario.tcc.model.Produto</class>
		
		<properties>
			<property name="javax.persistence.jdbc.url" 	 value="jdbc:postgresql://localhost:5432/multitenant"/>
			<property name="javax.persistence.jdbc.user" 	 value="postgres"/>
			<property name="javax.persistence.jdbc.password" value="postgres"/> 
			<property name="javax.persistence.jdbc.driver" 	 value="org.postgresql.Driver"/>
			
			<!-- configurações do eclipselink -->			
			<property name="eclipselink.target-database" 				value="PostgreSQL"/>
			<property name="eclipselink.jdbc.uppercase-columns" 		value="true" />
			<property name="eclipselink.jdbc.allow-native-sql-queries" 	value="true"/>
			 
		</properties>
		
	</persistence-unit>


Java Classes

@Entity
@Multitenant
@TenantDiscriminatorColumn(name="empresa_id", contextProperty="tenant.empresa", discriminatorType=DiscriminatorType.INTEGER)
public class Produto implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2739839954798051504L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long id;
	
	private String descricao;
	
	@ManyToOne
	@JoinColumn(name="empresa_id", insertable=false, updatable=false)
	private Empresa empresa;//tenant identifier

       //getters and setters .....


so... what I do? what is it? why this is happening?

follows the image of the database after the operations
  • Attachment: table.jpg
    (Size: 29.48KB, Downloaded 135 times)
Previous Topic:Listening for cache coordination
Next Topic:Randomly occurring missing parameter while using @Multitenant and @AdditionalCriteria
Goto Forum:
  


Current Time: Tue Mar 19 04:17:30 GMT 2024

Powered by FUDForum. Page generated in 0.01894 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top