Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 541046 : @JoinFetch doesn't work with default value #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// 12/02/2019-3.0 - Alexandre Jacob
// - 541046: @JoinFetch doesn't work with default value
package org.eclipse.persistence.jpa.test.mapping;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.eclipse.persistence.jpa.test.framework.DDLGen;
import org.eclipse.persistence.jpa.test.framework.Emf;
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
import org.eclipse.persistence.jpa.test.framework.Property;
import org.eclipse.persistence.jpa.test.mapping.model.JF1;
import org.eclipse.persistence.jpa.test.mapping.model.JF2;
import org.eclipse.persistence.jpa.test.mapping.model.JF3;
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
import org.eclipse.persistence.sessions.server.ServerSession;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(EmfRunner.class)
public class TestBatchFetchMapping {

@Emf(createTables = DDLGen.NONE, classes = { JF1.class, JF2.class, JF3.class },
properties = {
@Property(name = "eclipselink.logging.level.sql", value = "FINEST")
})
private EntityManagerFactory emf;

@Test
public void testBatchFetchWithDefaultValue() {
EntityManager em = emf.createEntityManager();

ForeignReferenceMapping mapping = (ForeignReferenceMapping)em.unwrap(ServerSession.class).getDescriptor(JF1.class).getMappingForAttributeName("jf2");

Assert.assertEquals(mapping.getJoinFetch(), ForeignReferenceMapping.INNER_JOIN);
}

@Test
public void testBatchFetchWithExplicitValue() {
EntityManager em = emf.createEntityManager();

ForeignReferenceMapping mapping = (ForeignReferenceMapping)em.unwrap(ServerSession.class).getDescriptor(JF2.class).getMappingForAttributeName("jf3");

Assert.assertEquals(mapping.getJoinFetch(), ForeignReferenceMapping.OUTER_JOIN);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// 12/02/2019-3.0 - Alexandre Jacob
// - 541046: @JoinFetch doesn't work with default value
package org.eclipse.persistence.jpa.test.mapping.model;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.eclipse.persistence.annotations.JoinFetch;

@Entity
public class JF1 {

@Id
private int id;

@ManyToOne
@JoinFetch
private JF2 jf2;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public JF2 getJf2() {
return jf2;
}

public void setJf2(JF2 jf2) {
this.jf2 = jf2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// 12/02/2019-3.0 - Alexandre Jacob
// - 541046: @JoinFetch doesn't work with default value
package org.eclipse.persistence.jpa.test.mapping.model;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.eclipse.persistence.annotations.JoinFetch;
import org.eclipse.persistence.annotations.JoinFetchType;

@Entity
public class JF2 {

@Id
private int id;

@ManyToOne
@JoinFetch(JoinFetchType.OUTER)
private JF3 jf3;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public JF3 getJf3() {
return jf3;
}

public void setJf3(JF3 jf3) {
this.jf3 = jf3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// 12/02/2019-3.0 - Alexandre Jacob
// - 541046: @JoinFetch doesn't work with default value
package org.eclipse.persistence.jpa.test.mapping.model;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class JF3 {

@Id
private int id;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -43,11 +43,14 @@
// - 374688: JPA 2.1 Converter support
// 07/16/2013-2.5.1 Guy Pelletier
// - 412384: Applying Converter for parameterized basic-type for joda-time's DateTime does not work
// 12/02/2019-3.0 Alexandre Jacob
// - 541046: @JoinFetch doesn't work with default value
package org.eclipse.persistence.internal.jpa.metadata.accessors.mappings;

import org.eclipse.persistence.annotations.BatchFetch;
import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.eclipse.persistence.annotations.JoinFetch;
import org.eclipse.persistence.annotations.JoinFetchType;
import org.eclipse.persistence.annotations.Noncacheable;
import org.eclipse.persistence.internal.helper.DatabaseTable;
import org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor;
Expand Down Expand Up @@ -116,7 +119,7 @@ protected DirectCollectionAccessor(MetadataAnnotation annotation, MetadataAccess

// Set the join fetch if one is present.
if (isAnnotationPresent(JoinFetch.class)) {
m_joinFetch = getAnnotation(JoinFetch.class).getAttributeString("value");
m_joinFetch = getAnnotation(JoinFetch.class).getAttributeString("value", JoinFetchType.INNER.name());
}

// Set the batch fetch if one is present.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -54,6 +54,8 @@
// - 389090: JPA 2.1 DDL Generation Support (foreign key metadata support)
// 11/28/2012-2.5 Guy Pelletier
// - 374688: JPA 2.1 Converter support
// 12/02/2019-3.0 Alexandre Jacob
// - 541046: @JoinFetch doesn't work with default value
package org.eclipse.persistence.internal.jpa.metadata.accessors.mappings;

import static org.eclipse.persistence.internal.jpa.metadata.MetadataConstants.JPA_COLUMN;
Expand All @@ -70,6 +72,7 @@
import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.eclipse.persistence.annotations.Convert;
import org.eclipse.persistence.annotations.JoinFetch;
import org.eclipse.persistence.annotations.JoinFetchType;
import org.eclipse.persistence.annotations.Noncacheable;
import org.eclipse.persistence.annotations.PrivateOwned;
import org.eclipse.persistence.exceptions.ValidationException;
Expand Down Expand Up @@ -152,7 +155,7 @@ protected RelationshipAccessor(MetadataAnnotation annotation, MetadataAccessible

// Set the join fetch if one is present.
if (isAnnotationPresent(JoinFetch.class)) {
m_joinFetch = getAnnotation(JoinFetch.class).getAttributeString("value");
m_joinFetch = getAnnotation(JoinFetch.class).getAttributeString("value", JoinFetchType.INNER.name());
}

// Set the batch fetch if one is present.
Expand Down