This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JPA + Glassfish + Netbeans+enity class + generate tables =(  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to generate database tables from annotated @entity classes for starters I'm just trying to generate anything:
1) I created a Derby database called DBtest.
2) I right clicked on the project and clicked 'new persistence unit'
3) under 'Data source' I clicked 'New Datasource'
4) jndi name : jdbc/testDB
Database Connection url: jdbc erby://localhost:1527/DBtest
persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="my_persistence_ctx">
<jta-data-source>jdbc/testDB</jta-data-source>
<properties>
<!--Use the java2db feature -->
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
<!-- Generate the sql specific to Derby database -->
<property name="toplink.platform.class.name"
value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
<property name="toplink.jdbc.user" value="test"/>
<property name="toplink.jdbc.password" value="test"/>
</properties>
</persistence-unit>
</persistence>

----------------------------------------------------------------------------

I have one entity class Person
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
*
* @author Administrator
*/
@Entity
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

public Long getId() {
return id;
}

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

@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 Person)) {
return false;
}
Person other = (Person) 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 "com.entity.Person[id=" + id + "]";
}

}

---------------------------------------------------------------------------
I build and clean it, then deploy it to glassfish...and according to my understanding the table Person should be created...but nada . It deploys fine without an exception, but no table is created. In fact, if i change the name inside <jta-data-source> to garbage there are still no exceptions, and it deploys fine...this leads me to believe the JNDI name is not registered properly in Glassfish. I'm not sure, but it is driving me nuts.
Any help would be GREATLY appreciated. Thanks!
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Odd that when you replace the datasource name with something invalid that you get no errors. Do you have logging on, and are you checking the correct log file?

In terms of creating the tables you may need to set the persistence property,
"toplink.ddl-generation.output-mode"="database"

To turn on logging you can set,
"toplink.logging.level"="finest"
"toplink.logging.logger"="DefaultLogger"
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!