Results 1 to 4 of 4
  1. #1
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    34
    Rep Power
    0

    Default JPA and Sax parser persistence issue

    Hello,

    I am wondering if anyone can offer any advice. I have been working flat out on this the last couple of days and I am getting no where.

    I have a eclipse project - with some java classes and an entity manager.

    I am looking to know in pusecode how the code should be structured


    I have a main class file class Main {}

    I have a getter/setter class file - file GetterSetter{}

    I have an entity manager class file - file EntityManager{}

    Java Code:
    public class EntityManager
    @Action(Action.ACTION_TYPE.CREATE)
    	public String createData(Data Data)
    			throws Exception {
    	//	System.out.println("begining the transaction");
    		EntityManager em = getEntityManager();
    	//	System.out.println("get entity manger");
    		try {
    			em.getTransaction().begin();
    			em.persist(northRawData);
    			em.getTransaction().commit();
    			
    		} catch (Exception ex) {
    			try {
    				if (em.getTransaction().isActive()) {
    					em.getTransaction().rollback();
    				}
    			} catch (Exception e) {
    				ex.printStackTrace();
    				throw e;
    			}
    			throw ex;
    		} finally {
    			em.close();
    		}
    		return "";
    	}


    Java Code:
    public class GettersSetters implements Serializable {
    	
    public String getId() {
    		return this.id;
    	}
    
    	public void setId(String id) {
    
    		this.id = id;
    		
    	}
    
    
    	
    	}

    Java Code:
    public class Main extends DefaultHandler {
    
            GetterSetter Tmp;
    	EntityManagerFactory EntityManagerFactory;
    	EntityManager manager;
    	String tmpString;
    
    	//creating the main constructor
        	public Main() throws IOException, SAXException{
        		
        		Tmp = new GetterSetter(); 
    
    
    public void startDocument(){
        	
        	    }
        	
        public void endDocument(){
        	
    		
        }
        
        	
    	@Override
    	 
    	public void startElement(String uri, String localName,String qName, Attributes attributes) throws SAXException {
    		
        	  EntityManagerFactory	 =  Persistence.createEntityManagerFactory("northSax");
        	  manager = new EntityManager(entityManagerFactory);
    if(qName.equalsIgnoreCase("object")&&("ok".equalsIgnoreCase(attributes.getValue("status"))))
    		{	
    			
    			 try {
    				 	Tmp.setId(attributes.getValue("id"));
    					
    
    					manager.createEntityManager(Tmp);
    				} catch (Exception e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				
    			
    			object=true;
    			
    		}
    
    @Override
    	public void endElement(String uri, String localName,String qName) throws SAXException {
    	
    	
    		if(qName.equals("object")){
    			object=false;
    		}
    
    
    		
    		if(qName.equalsIgnoreCase("label")){
    			
    			
    				
    				Tmp.setLabel(String.valueOf(tmp));
    		;
    			
    		
    	//		
    			label=false;
    		}
    
    }

    I am getting problems with the code. The data is now coming in as null where before the data was coming in but not return null for a null value. It was taking the last non null value and putting that into a null value field.


    Can somewhere give me a simple document with sax parses / jpa and jpa entity manager working so that I can look at it for analysis. I dont really know where I should be putting the
    EntityManagerFactory = Persistence.createEntityManagerFactory("northSax") ;
    manager = new EntityManager(entityManagerFactory);

    AND

    manager.create(Tmp);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    Thanks in advance
    Last edited by alexandra12; 08-17-2012 at 01:10 AM.

  2. #2
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    34
    Rep Power
    0

    Default Re: JPA and Sax parser persistence issue

    Anandhi - can you post your problem in a separate post ? as I am still looking for an answer to this problem.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: JPA and Sax parser persistence issue

    I've removed the thread hijack.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    34
    Rep Power
    0

    Default Re: JPA and Sax parser persistence issue

    this problem is now resolved !

Similar Threads

  1. Persistence API with Java SE?
    By FlyNn in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 02-14-2012, 10:47 PM
  2. jboss 6 persistence
    By vikt0r87 in forum New To Java
    Replies: 1
    Last Post: 10-23-2011, 03:51 PM
  3. persistence NULLs
    By flanjl2 in forum Advanced Java
    Replies: 1
    Last Post: 09-21-2011, 04:59 AM
  4. Persistence
    By frexjeff in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2011, 04:03 PM
  5. help me with persistence
    By halyal in forum NetBeans
    Replies: 14
    Last Post: 09-04-2010, 10:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •