NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Problems with creating entities from database in NB 6.9.1

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
anaq



Joined: 21 Sep 2009
Posts: 44

PostPosted: Tue Aug 17, 2010 11:43 am    Post subject: Problems with creating entities from database in NB 6.9.1 Reply with quote

Hi all,

I've moved from NB 6.8 to 6.9.1 and I've found out very unexpected behaviour. I like to know, if they're bugs, new "features" or something else...

1. When I'm creating an entity from database and this entity has foreign keys from other tables (entities), NB wants to create all these entities, even if they already exist (if in the same package, the old entity classes are replaced with the new ones). When I deselect the option "Include related tables", the new entity class misses the relations (manytoone,...).

2. When the entity has more relations to an other entity, NB generates the field names not correct. This example is from my project:
Cashflow has two Currencies, NB generates this:
@JoinColumn(name = "provisioncurrency", referencedColumnName = "id")
@ManyToOne(fetch = FetchType.EAGER)
private Currency currency1;
@JoinColumn(name = "currency", referencedColumnName = "id")
@ManyToOne(fetch = FetchType.EAGER)
private Currency currency2;

I've expected:
@JoinColumn(name = "provisioncurrency", referencedColumnName = "id")
@ManyToOne(fetch = FetchType.EAGER)
private Currency provisioncurrency;
@JoinColumn(name = "currency", referencedColumnName = "id")
@ManyToOne(fetch = FetchType.EAGER)
private Currency currency;

Has anybody found out the same behaviour? Is it normal?
Back to top
javydreamercsw



Joined: 22 Jun 2009
Posts: 456

PostPosted: Tue Aug 17, 2010 11:56 am    Post subject: Problems with creating entities from database in NB 6.9.1 Reply with quote

Usually that happens but they are marked as Update or Recreate in the last step of the wizard. If not that would be a bug.

On Tue, Aug 17, 2010 at 6:43 AM, anaq <address-removed ([email]address-removed[/email])> wrote:
Quote:
Hi all,

I've moved from NB 6.8 to 6.9.1 and I've found out very unexpected behaviour. I like to know, if they're bugs, new "features" or something else...

1. When I'm creating an entity from database and this entity has foreign keys from other tables (entities), NB wants to create all these entities, even if they already exist (if in the same package, the old entity classes are replaced with the new ones). When I deselect the option "Include related tables", the new entity class misses the relations (manytoone,...).

2. When the entity has more relations to an other entity, NB generates the field names not correct. This example is from my project:
Cashflow has two Currencies, NB generates this:
@JoinColumn(name = "provisioncurrency", referencedColumnName = "id")
   @ManyToOne(fetch = FetchType.EAGER)
   private Currency currency1;
   @JoinColumn(name = "currency", referencedColumnName = "id")
   @ManyToOne(fetch = FetchType.EAGER)
   private Currency currency2;

I've expected:
@JoinColumn(name = "provisioncurrency", referencedColumnName = "id")
   @ManyToOne(fetch = FetchType.EAGER)
   private Currency provisioncurrency;
   @JoinColumn(name = "currency", referencedColumnName = "id")
   @ManyToOne(fetch = FetchType.EAGER)
   private Currency currency;

Has anybody found out the same behaviour? Is it normal?




Back to top
anaq



Joined: 21 Sep 2009
Posts: 44

PostPosted: Tue Aug 17, 2010 12:19 pm    Post subject: Re: Reply with quote

Thank you for answer.

I don't see any Update or Recreate options in the wizard steps. Only in 3. step (entity classes), is in the table of new classes column GenerationType, but there is only NEW option in the combobox menu...
Back to top
Javier.Ortiz
Posted via mailing list.





PostPosted: Tue Aug 17, 2010 4:46 pm    Post subject: Problems with creating entities from database in NB 6.9.1 Reply with quote

Can I see the entity classes? Something's fishy...

Javier A. Ortiz Bultr
Back to top
anaq



Joined: 21 Sep 2009
Posts: 44

PostPosted: Tue Aug 17, 2010 6:28 pm    Post subject: Re: Reply with quote

I've done this simple test case. Class Currency already exists in my project, I've added a new table test to the database, SQL:
Code:

CREATE  TABLE IF NOT EXISTS `test` (
  `id` INT(11) NOT NULL ,
  `currency` INT(3) NOT NULL ,
  `provisioncurrency` INT(3) NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_test_currency1` (`currency` ASC) ,
  INDEX `fk_test_currency2` (`provisioncurrency` ASC) ,
  CONSTRAINT `fk_test_currency1`
    FOREIGN KEY (`currency` )
    REFERENCES `currency` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_test_currency2`
    FOREIGN KEY (`provisioncurrency` )
    REFERENCES `currency` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

Recapturing schema from database doesn't help, I can not see the new table, so I need to delete and create the schema.
I try to add new entity class from database - only test table is not grey. When I click on add button, test and currency are moved to the right list (currency is grey).
After this NB 6.9.1 generates both classes - Test and Currency.

Test class:
Code:

@Entity
@Table(name = "test")
@NamedQueries({
    @NamedQuery(name = "Test.findAll", query = "SELECT t FROM Test t"),
    @NamedQuery(name = "Test.findById", query = "SELECT t FROM Test t WHERE t.id = :id")})
public class Test implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @JoinColumn(name = "provisioncurrency", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Currency currency;
    @JoinColumn(name = "currency", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Currency currency1;

    public Test() {
    }

    public Test(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

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

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public Currency getCurrency1() {
        return currency1;
    }

    public void setCurrency1(Currency currency1) {
        this.currency1 = currency1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Test)) {
            return false;
        }
        Test other = (Test) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id.toString();
    }

}


Currency class:
Code:

@Entity
@Table(name = "currency")
@NamedQueries({
    @NamedQuery(name = "Currency.findAll", query = "SELECT c FROM Currency c"),
    @NamedQuery(name = "Currency.findById", query = "SELECT c FROM Currency c WHERE c.id = :id"),
    @NamedQuery(name = "Currency.findByName", query = "SELECT c FROM Currency c WHERE c.name = :name")})
public class Currency implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "currency")
    private Collection<Test> testCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "currency1")
    private Collection<Test> testCollection1;

    public Currency() {
    }

    public Currency(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    public Collection<Test> getTestCollection() {
        return testCollection;
    }

    public void setTestCollection(Collection<Test> testCollection) {
        this.testCollection = testCollection;
    }

    public Collection<Test> getTestCollection1() {
        return testCollection1;
    }

    public void setTestCollection1(Collection<Test> testCollection1) {
        this.testCollection1 = testCollection1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Currency)) {
            return false;
        }
        Currency other = (Currency) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id.toString();
    }

}


I've modified toString() methods.

The Currency class shows this error: "Duplicate entity name. Class ...Currency is using the same name."
Back to top
Javier.Ortiz
Posted via mailing list.





PostPosted: Tue Aug 17, 2010 8:55 pm    Post subject: Problems with creating entities from database in NB 6.9.1 Reply with quote

This looks like a bug indeed. The culprit, I assume, is the CascadeType.ALL in the Test class. That basically forces the entity to be created if I'm correct. Try changing that to another value.

Javier A. Ortiz Bultr
Back to top
Antonio Varela
Posted via mailing list.





PostPosted: Wed Aug 18, 2010 6:05 am    Post subject: Problems with creating entities from database in NB 6.9.1 Reply with quote

On Tue, Aug 17, 2010 at 4:43 AM, anaq <address-removed> wrote:

Quote:
1. When I'm creating an entity from database and this entity has foreign keys from other tables (entities), NB wants to create all these entities, even if they already exist (if in the same package, the old entity classes are replaced with the new ones). When I deselect the option "Include related tables", the new entity class misses the relations (manytoone,...).



I can confirm this problem. It worked fine in NB6.7.1.

Best regards.
--
Antonio Varela
address-removed
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo