[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-5041) @ManyToOne not working with @Formula

Sharath Reddy (JIRA) noreply at atlassian.com
Wed Apr 28 10:22:28 EDT 2010


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5041?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sharath Reddy closed HHH-5041.
------------------------------

    Resolution: Won't Fix

Correct Mapping:
@Entity
@Table(name="product")
public class Product implements Serializable
{
	
	private static final long serialVersionUID = 6956478993159505828L;

	@Id
    public Integer id;
    
    @Column(name="product_idnf", length=18, nullable=false, unique=true,
        columnDefinition="char(18)")
    public String productIdnf;
    
    @Column(name="description", nullable=false)
    public String description;

    @ManyToOne
	@JoinColumnsOrFormulas(
	{ 
		@JoinColumnOrFormula(formula=@JoinFormula(value="SUBSTR(product_idnf, 1, 3)", 
				referencedColumnName="product_idnf"))
	})
    @Fetch(FetchMode.JOIN)
    private Product productFamily;
    
    public Product getProductFamily()
    {
        return productFamily;
    }
   
}

And this is the test case I ran:
public void testFailing() throws Exception
    {
		
		Session s = openSession();
		Transaction tx = s.beginTransaction();
		
        Product kit = new Product();
        kit.id = 1;
        kit.productIdnf = "KIT";
        kit.description = "Kit";
        s.persist(kit);
        
        Product kitkat = new Product();
        kitkat.id = 2;
        kitkat.productIdnf = "KIT_KAT";
        kitkat.description = "Chocolate";
        s.persist(kitkat);
        
        s.flush();
        s.clear();    
        
        kit = (Product) s.get(Product.class, 1);
        kitkat = (Product) s.get(Product.class, 2);
        System.out.println(kitkat.description);
        assertNotNull(kitkat);
        assertEquals(kit, kitkat.getProductFamily());
        assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
        assertEquals("KIT_KAT", kitkat.productIdnf.trim());
        assertEquals("Chocolate", kitkat.description.trim());
                
        tx.rollback();
		s.close();
    }    


> @ManyToOne not working with @Formula
> ------------------------------------
>
>                 Key: HHH-5041
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5041
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations
>    Affects Versions: 3.5.0-CR-2
>            Reporter: Chris Wilson
>            Assignee: Sharath Reddy
>         Attachments: HibernateAnnotationJoinOnFormulaTest.java
>
>
> HHH-4382 was marked as resolved fixed in 3.5. However, I cannot find the fix, and it appears still to be broken for me.
> The attached test case fails with 3.5.0-CR-2 just as it did with 3.3.2. It seems to ignore the @Formula annotation and simply create a productFamily column, which is of course empty.
> If I am doing something wrong, please could you tell me what it is, so that I can fix my code?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list