0

我正在尝试将 LinkedList 放入 @Embeddable @ElementCollection 并给我: org.hibernate.MappingException

主要的:

public class Main 
{
    @SuppressWarnings({ "deprecation", "static-access" })
    public static void main(String[] args)
    {
        AdvertiserDAO adD = new AdvertiserDAO();
        Advertiser ad = new Advertiser();
        Campaign c = new Campaign();
        Action ac = new Action();
        Calendar start = new GregorianCalendar();
        Calendar end = new GregorianCalendar();

        start.set(Calendar.DAY_OF_MONTH,8);
        start.set(Calendar.MONTH,0);
        start.set(Calendar.YEAR,2018);
        start.set(Calendar.HOUR_OF_DAY,12);
        start.set(Calendar.MINUTE, 0);
        start.set(Calendar.SECOND, 0);

        end.set(Calendar.DAY_OF_MONTH,1);
        end.set(Calendar.MONTH,11);
        end.set(Calendar.YEAR,2018);
        end.set(Calendar.HOUR_OF_DAY,13);
        end.set(Calendar.MINUTE, 30);
        end.set(Calendar.SECOND, 10);

        System.out.println("Start date: "+start.get(Calendar.DAY_OF_MONTH)+"/"+(start.get(Calendar.MONTH)+1)+"/"+start.get(Calendar.YEAR));
        System.out.println("Start time: "+start.get(Calendar.HOUR_OF_DAY)+":"+start.get(Calendar.MINUTE)+":"+start.get(Calendar.SECOND));

        System.out.println("End date: "+end.get(Calendar.DAY_OF_MONTH)+"/"+(end.get(Calendar.MONTH)+1)+"/"+end.get(Calendar.YEAR));
        System.out.println("End time: "+end.get(Calendar.HOUR_OF_DAY)+":"+end.get(Calendar.MINUTE)+":"+end.get(Calendar.SECOND));

        /*Set Action properties*/
        ac.setStartDate(start);
        ac.setEndDate(end);
        ac.setId("1");


        /*Set Campaign properties*/
        c.addIdAction(ac.getId());
        c.setStartDate(start);
        c.setEndDate(end);
        c.setDefaultURL("http://www.facebook.com");         

        /*Set advertiser properties*/
        ad.setActive(true);
        ad.setAdress("Fake street 123");
        ad.setEmail("mail@gmail.com");
        ad.setId("17");
        ad.setName("Name Inc.");
        ad.setPhone("000000000");
        ad.setProduct("Product");
        ad.setSector("IT");
        ad.setDefaultURL("http://www.twitter.com");
        ad.setSubSector("Software development");
        ad.addCampaign(c);

        System.out.println(ad);

        adD.create(ad);




    }
}

主要实体:

@Entity
public class Advertiser 
{
    @Id
    private String id;

    private boolean active;

    private String name;

    private String adress;

    private String phone;

    private String email;

    private String product;

    private String sector;

    private String subSector;

    private String defaultURL;

    @Embedded
    @ElementCollection(targetClass=Campaign.class)
    private List<Campaign> campaigns;

    public Advertiser()
    {

    }

    public String getId() {
        return id;
    }

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

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getSector() {
        return sector;
    }

    public void setSector(String sector) {
        this.sector = sector;
    }

    public String getSubSector() {
        return subSector;
    }

    public void setSubSector(String subSector) {
        this.subSector = subSector;
    }

    public String getDefaultURL() {
        return defaultURL;
    }

    public void setDefaultURL(String defaultURL) {
        this.defaultURL = defaultURL;
    }

    public List<Campaign> getCampaigns() {
        return campaigns;
    }

    public void setCampaigns(List<Campaign> campaigns) {
        this.campaigns = campaigns;
    }
    public void addCampaign(Campaign campaign)
    {
        if(this.campaigns == null)
        {
            this.campaigns = new LinkedList<Campaign>();
        }
        this.campaigns.add(campaign);
    }

    @Override
    public String toString() {
        return "Advertiser [id=" + id + ", active=" + active + ", name=" + name + ", adress=" + adress + ", phone="
                + phone + ", email=" + email + ", product=" + product + ", sector=" + sector + ", subSector="
                + subSector + ", defaultURL=" + defaultURL + ", \ncampaigns:\n  " + campaigns + "]\n";
    }



}

嵌入式类:

@Embeddable
public class Campaign 
{
    private Calendar startDate;

    private Calendar endDate;

    private String defaultURL;

    private List<String> idActions;

    //TODO: specific getters and setters, getDay, getMonth, getYear, getHour, getMinute, getSecond
    public String getDefaultURL() {
        return defaultURL;
    }
    public void setDefaultURL(String defaultURL) {
        this.defaultURL = defaultURL;
    }
    public Calendar getStartDate() {
        return startDate;
    }
    public void setStartDate(Calendar startDate) {
        this.startDate = startDate;
    }
    public Calendar getEndDate() {
        return endDate;
    }
    public void setEndDate(Calendar endDate) {
        this.endDate = endDate;
    }
    public List<String> getIdAction() {
        return idActions;
    }
    public void setIdAction(List<String> idAction) {
        this.idActions = idAction;
    }
    public void addIdAction(String idAction)
    {
        if(this.idActions == null)
        {
            this.idActions = new LinkedList<String>();
        }
        this.idActions.add(idAction);
    }       
}

错误:

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: DP] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
    at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:59)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at com.MOVASIM.IoTekLink.persistence.jpa.Factory.getEntityManager(Factory.java:16)
    at com.MOVASIM.IoTekLink.persistence.jpa.JPADAO.create(JPADAO.java:14)
    at com.MOVASIM.IoTekLink.main.Main.main(Main.java:63)
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Advertiser_campaigns, for columns: [org.hibernate.mapping.Column(campaigns.idActions.idActions)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:396)
    at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:267)
    at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:54)
    at org.hibernate.mapping.Component.getType(Component.java:169)
    at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:267)
    at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:54)
    at org.hibernate.mapping.Component.getType(Component.java:169)
    at org.hibernate.mapping.Property.getCascadeStyle(Property.java:101)
    at org.hibernate.tuple.PropertyFactory.buildEntityBasedAttribute(PropertyFactory.java:229)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:208)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:509)
    at org.hibernate.ogm.persister.impl.OgmEntityPersister.<init>(OgmEntityPersister.java:199)
    at org.hibernate.ogm.persister.impl.SingleTableOgmEntityPersister.<init>(SingleTableOgmEntityPersister.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:346)
    at org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:54)
    at org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:23)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
    ... 7 more

当我尝试在数据库中创建 Advertiser 对象时出现错误跳转。

4

0 回答 0